# `SemanticVersion`

A software version: `1.2.3-alpha.1+build.5`.

Use it for your own or a package's release number. `<` compares two the way versions are meant to compare. For a range such as `^1.2`, use [`VersionRange`](/docs/types/type-version-range.md).

## Shape

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

Write every field when you build one, and give a field that isn't required as `none`.

## Example

```jadpo
SemanticVersion { major: 1 minor: 2 patch: 3 pre_release: none build: none }
```

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

## Good to know

- `text.parse` reads `1.2.3`. A `v` at the front and `1.0` are refused, so give all three numbers.
- Build metadata, the part after `+`, is ignored when ordering.
- `==` tells you whether two are the same, and `<` and `list.sort_by` compare and sort them.

## In JSON

A string, in a request, a response or `json.write`:

```json
"1.0.0-alpha"
"1.0.0-alpha.1"
"1.0.0-alpha.beta"
```

When you read one, a field that isn't required may be left out, or sent as `null`.

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`SemanticVersion` is in the group Software, and has been in Jadpo since 0.1.0.

### Text form

`text.from` writes one standard text form, the same form `text.parse` reads back: `1.0.0-alpha`, `1.0.0-alpha.1` and `1.0.0-alpha.beta`.

### How it is stored

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` |

### How it is 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`.

It also takes `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
