1 semver(1) -- The semantic versioner for npm
2 ===========================================
8 semver.valid('1.2.3') // '1.2.3'
9 semver.valid('a.b.c') // null
10 semver.clean(' =v1.2.3 ') // '1.2.3'
11 semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
12 semver.gt('1.2.3', '9.8.7') // false
13 semver.lt('1.2.3', '9.8.7') // true
15 As a command-line utility:
19 Usage: semver <version> [<version> [...]] [-r <range> | -i <inc> | -d <dec>]
20 Test if version(s) satisfy the supplied range(s), and sort them.
22 Multiple versions or ranges may be supplied, unless increment
23 or decrement options are specified. In that case, only a single
24 version may be used, and it is incremented by the specified level
26 Program exits successfully if any valid version satisfies
27 all supplied ranges, and prints all satisfying versions.
29 If no versions are valid, or ranges are not satisfied,
32 Versions are printed in ascending order, so supplying
33 multiple versions to the utility will just sort them.
37 A "version" is described by the v2.0.0 specification found at
40 A leading `"="` or `"v"` character is stripped off and ignored.
44 The following range styles are supported:
46 * `1.2.3` A specific version. When nothing else will do. Note that
47 build metadata is still ignored, so `1.2.3+build2012` will satisfy
49 * `>1.2.3` Greater than a specific version.
50 * `<1.2.3` Less than a specific version. If there is no prerelease
51 tag on the version range, then no prerelease version will be allowed
52 either, even though these are technically "less than".
53 * `>=1.2.3` Greater than or equal to. Note that prerelease versions
54 are NOT equal to their "normal" equivalents, so `1.2.3-beta` will
55 not satisfy this range, but `2.3.0-beta` will.
56 * `<=1.2.3` Less than or equal to. In this case, prerelease versions
57 ARE allowed, so `1.2.3-beta` would satisfy.
58 * `1.2.3 - 2.3.4` := `>=1.2.3 <=2.3.4`
59 * `~1.2.3` := `>=1.2.3-0 <1.3.0-0` "Reasonably close to 1.2.3". When
60 using tilde operators, prerelease versions are supported as well,
61 but a prerelease of the next significant digit will NOT be
62 satisfactory, so `1.3.0-beta` will not satisfy `~1.2.3`.
63 * `^1.2.3` := `>=1.2.3-0 <2.0.0-0` "Compatible with 1.2.3". When
64 using caret operators, anything from the specified version (including
65 prerelease) will be supported up to, but not including, the next
66 major version (or its prereleases). `1.5.1` will satisfy `^1.2.3`,
67 while `1.2.2` and `2.0.0-beta` will not.
68 * `^0.1.3` := `>=0.1.3-0 <0.2.0-0` "Compatible with 0.1.3". 0.x.x versions are
69 special: the first non-zero component indicates potentially breaking changes,
70 meaning the caret operator matches any version with the same first non-zero
71 component starting at the specified version.
72 * `^0.0.2` := `=0.0.2` "Only the version 0.0.2 is considered compatible"
73 * `~1.2` := `>=1.2.0-0 <1.3.0-0` "Any version starting with 1.2"
74 * `^1.2` := `>=1.2.0-0 <2.0.0-0` "Any version compatible with 1.2"
75 * `1.2.x` := `>=1.2.0-0 <1.3.0-0` "Any version starting with 1.2"
76 * `~1` := `>=1.0.0-0 <2.0.0-0` "Any version starting with 1"
77 * `^1` := `>=1.0.0-0 <2.0.0-0` "Any version compatible with 1"
78 * `1.x` := `>=1.0.0-0 <2.0.0-0` "Any version starting with 1"
81 Ranges can be joined with either a space (which implies "and") or a
82 `||` (which implies "or").
86 All methods and classes take a final `loose` boolean argument that, if
87 true, will be more forgiving about not-quite-valid semver strings.
88 The resulting output will always be 100% strict, of course.
90 Strict-mode Comparators and Ranges will be strict about the SemVer
91 strings that they parse.
93 * valid(v): Return the parsed version, or null if it's not valid.
94 * inc(v, release): Return the version incremented by the release type
95 (major, minor, patch, or prerelease), or null if it's not valid.
99 * gt(v1, v2): `v1 > v2`
100 * gte(v1, v2): `v1 >= v2`
101 * lt(v1, v2): `v1 < v2`
102 * lte(v1, v2): `v1 <= v2`
103 * eq(v1, v2): `v1 == v2` This is true if they're logically equivalent,
104 even if they're not the exact same string. You already know how to
106 * neq(v1, v2): `v1 != v2` The opposite of eq.
107 * cmp(v1, comparator, v2): Pass in a comparison string, and it'll call
108 the corresponding function above. `"==="` and `"!=="` do simple
109 string comparison, but are included for completeness. Throws if an
110 invalid comparison string is provided.
111 * compare(v1, v2): Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if
112 v2 is greater. Sorts in ascending order if passed to Array.sort().
113 * rcompare(v1, v2): The reverse of compare. Sorts an array of versions
114 in descending order when passed to Array.sort().
119 * validRange(range): Return the valid range or null if it's not valid
120 * satisfies(version, range): Return true if the version satisfies the
122 * maxSatisfying(versions, range): Return the highest version in the list
123 that satisfies the range, or null if none of them do.
124 * gtr(version, range): Return true if version is greater than all the
125 versions possible in the range.
126 * ltr(version, range): Return true if version is less than all the
127 versions possible in the range.
128 * outside(version, range, hilo): Return true if the version is outside
129 the bounds of the range in either the high or low direction. The
130 `hilo` argument must be either the string `'>'` or `'<'`. (This is
131 the function called by `gtr` and `ltr`.)
133 Note that, since ranges may be non-contiguous, a version might not be
134 greater than a range, less than a range, *or* satisfy a range! For
135 example, the range `1.2 <1.2.9 || >2.0.0` would have a hole from `1.2.9`
136 until `2.0.0`, so the version `1.2.10` would not be greater than the
137 range (because 2.0.1 satisfies, which is higher), nor less than the
138 range (since 1.2.8 satisfies, which is lower), and it also does not
141 If you want to know if a version satisfies or does not satisfy a
142 range, use the `satisfies(version, range)` function.