# `SemanticVersion`

A version (SemVer 2.0.0), written `1.2.3-alpha.1+build.5`: ordered by its precedence, which ignores the build metadata.

[Software](types.md#software); ordered; since Jadpo 0.1.0.

## Make one

Build one from its fields, `SemanticVersion { major: ...  minor: ...  patch: ... }`.

`text.parse(raw, as: SemanticVersion)` reads one from its text; text that isn't one at all fails `malformed`, such as `v1.0.0`, `1.0` or `1.0.0.0`.

## Fields

| Field | Type |
|---|---|
| `major` | `Int` |
| `minor` | `Int` |
| `patch` | `Int` |
| `pre_release` | `Text?` |
| `build` | `Text?` |

## Text, JSON and storage

`text.from` writes its canonical text, the one form `text.parse` reads back. JSON sends its canonical text as a string.

| Text | JSON |
|---|---|
| `1.0.0-alpha` | `"1.0.0-alpha"` |
| `1.0.0-alpha.1` | `"1.0.0-alpha.1"` |
| `1.0.0-alpha.beta` | `"1.0.0-alpha.beta"` |
| `1.0.0-beta` | `"1.0.0-beta"` |
| `1.0.0-beta.2` | `"1.0.0-beta.2"` |
| `1.0.0-beta.11` | `"1.0.0-beta.11"` |
| `1.0.0-rc.1` | `"1.0.0-rc.1"` |
| `1.0.0` | `"1.0.0"` |
| `1.9.0` | `"1.9.0"` |
| `1.10.0+build.5` | `"1.10.0+build.5"` |
| `2.0.0` | `"2.0.0"` |

It is stored in 5 columns, each named for the field, `_` and its suffix. This is `1.0.0-beta.11`:

| Column | Type | Holds |
|---|---|---|
| `<field>_major` | `bigint` | `1` |
| `<field>_minor` | `bigint` | `0` |
| `<field>_patch` | `bigint` | `0` |
| `<field>_pre_release` | `text` | `'beta.11'` |
| `<field>_build` | `text` | `NULL::text` |

## Shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `1.0.0-alpha` | `1.0.0-alpha` |
| `1.0.0-alpha.1` | `1.0.0-alpha.1` |
| `1.0.0-alpha.beta` | `1.0.0-alpha.beta` |
| `1.0.0-beta` | `1.0.0-beta` |
| `1.0.0-beta.2` | `1.0.0-beta.2` |
| `1.0.0-beta.11` | `1.0.0-beta.11` |
| `1.0.0-rc.1` | `1.0.0-rc.1` |
| `1.0.0` | `1.0.0` |
| `1.9.0` | `1.9.0` |
| `1.10.0+build.5` | `1.10.0+build.5` |
| `2.0.0` | `2.0.0` |

## Operations

- `semver.satisfies(version: SemanticVersion, range: VersionRange) -> Bool`: Whether `version` is inside `range`, as node-semver reads the range: in one of its sets joined by `||`, meeting each comparison of it. A pre-release is inside only where a comparison of that set names a pre-release of the same major, minor and patch, so `^1.2.3` never takes `2.0.0-beta.1`.

Like every standard type, it also has the contract's own operations: `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. It is ordered, so `<` and sorting take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
