The semantic versioner for npm
The npm semantic versioning utility.
As a node module:
$ npm install semver
semver.valid('1.2.3') // '1.2.3'
semver.valid('a.b.c') // null
semver.clean(' =v1.2.3 ') // '1.2.3'
semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
semver.gt('1.2.3', '9.8.7') // false
semver.lt('1.2.3', '9.8.7') // true
As a command-line utility:
$ npm install semver -g
$ semver -h
Usage: semver -v <version> [-r <range>]
Test if version(s) satisfy the supplied range(s),
and sort them.
Multiple versions or ranges may be supplied.
Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.
If no versions are valid, or ranges are not satisfied,
then exits failure.
Versions are printed in ascending order, so supplying
multiple versions to the utility will just sort them.
A version is the following things, in this order:
A leading "="
or "v"
character is stripped off and ignored.
The ordering of versions is done using the following algorithm, given two versions and asked to find the greater of the two:
2.3.4 > 1.3.4
2.3.4 > 2.2.4
2.3.4 > 2.3.3
2.3.4-0 > 2.3.4
2.3.4-10 > 2.3.4-9
2.3.4 > 2.3.4-beta
2.3.4-beta > 2.3.4-alpha
The following range styles are supported:
>1.2.3
Greater than a specific version.<1.2.3
Less than1.2.3 - 2.3.4
:= >=1.2.3 <=2.3.4
~1.2.3
:= >=1.2.3 <1.3.0
~1.2
:= >=1.2.0 <1.3.0
~1
:= >=1.0.0 <2.0.0
1.2.x
:= >=1.2.0 <1.3.0
1.x
:= >=1.0.0 <2.0.0
Ranges can be joined with either a space (which implies "and") or a
||
(which implies "or").
v1 > v2
v1 >= v2
v1 < v2
v1 <= v2
v1 == v2
This is true if they're logically equivalent,
even if they're not the exact same string. You already know how to
compare strings.v1 != v2
The opposite of eq."==="
and "!=="
do simple
string comparison, but are included for completeness. Throws if an
invalid comparison string is provided.