Parse a SemVer string.
@eryx/semver Module
Semantic version parsing, comparison, and range matching.
Supported range selectors:
- exact:
1.2.3,=1.2.3 - comparators:
<1.2.3,<=1.2.3,>1.2.3,>=1.2.3 - caret:
^1.2.3 - tilde:
~1.2.3 - AND by whitespace:
>=1.2.3 <2.0.0 - OR by
||:^1.2.3 || ^2.0.0
^ means "compatible with this version". For stable versions it allows
changes below the next major version:
^1.2.3 := >=1.2.3 <2.0.0
For 0.x versions, compatibility is narrower because 0.x is considered
unstable:
^0.2.3 := >=0.2.3 <0.3.0
^0.0.3 := >=0.0.3 <0.0.4
~ means "approximately this version". It allows patch updates within the
same minor version:
~1.2.3 := >=1.2.3 <1.3.0
Summary
Functions
API Reference
Functions
semver.tryParse
Parse a SemVer string, returning nil instead of raising on invalid input.
semver.formatRange
Return a normalized SemVer range string.
semver.compare
Compare two versions.
Returns -1 when a < b, 1 when a > b, and 0 when they have equal
precedence. Build metadata is ignored.
semver.greaterThanOrEqual
semver.satisfies
Return whether version satisfies selector.