# `VersionRange`

A range of versions (node-semver's grammar in one spelling): `^1.2.3`, `>=1.0.0 <2.0.0`, `1.2.x || >=2.5.0-beta.1`.

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

## Make one

Build one from its text, `VersionRange("^1.2.3")`, which checks it: text that isn't one breaks `format`.

`text.parse(raw, as: VersionRange)` reads one from its text; text that isn't one at all fails `malformed`, such as `^v1.2.3`, `=1.2.3` or `>= 1.0.0`.

## 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.2.3` | `"^1.2.3"` |
| `~1.2` | `"~1.2"` |
| `>=1.0.0 <2.0.0` | `">=1.0.0 <2.0.0"` |
| `1.2.x \|\| >=2.5.0-beta.1` | `"1.2.x \|\| >=2.5.0-beta.1"` |
| `1.0.0 - 1.4.2` | `"1.0.0 - 1.4.2"` |
| `*` | `"*"` |
| `2.0.0` | `"2.0.0"` |

It is stored in one column named for the field, of type `text`. `1.2.x || >=2.5.0-beta.1` is stored as `'1.2.x || >=2.5.0-beta.1'`.

## Shown to people

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

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `^1.2.3` | `^1.2.3` |
| `~1.2` | `~1.2` |
| `>=1.0.0 <2.0.0` | `>=1.0.0 <2.0.0` |
| `1.2.x \|\| >=2.5.0-beta.1` | `1.2.x \|\| >=2.5.0-beta.1` |
| `1.0.0 - 1.4.2` | `1.0.0 - 1.4.2` |
| `*` | `*` |
| `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 isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
