1 .TH "SEMVER" "7" "October 2016" "" ""
3 \fBsemver\fR \- The semantic versioner for npm
10 semver\.valid('1\.2\.3') // '1\.2\.3'
11 semver\.valid('a\.b\.c') // null
12 semver\.clean(' =v1\.2\.3 ') // '1\.2\.3'
13 semver\.satisfies('1\.2\.3', '1\.x || >=2\.5\.0 || 5\.0\.0 \- 7\.2\.3') // true
14 semver\.gt('1\.2\.3', '9\.8\.7') // false
15 semver\.lt('1\.2\.3', '9\.8\.7') // true
19 As a command\-line utility:
25 Usage: semver <version> [<version> [\.\.\.]] [\-r <range> | \-i <inc> | \-\-preid <identifier> | \-l | \-rv]
26 Test if version(s) satisfy the supplied range(s), and sort them\.
28 Multiple versions or ranges may be supplied, unless increment
29 option is specified\. In that case, only a single version may
30 be used, and it is incremented by the specified level
32 Program exits successfully if any valid version satisfies
33 all supplied ranges, and prints all satisfying versions\.
35 If no versions are valid, or ranges are not satisfied,
38 Versions are printed in ascending order, so supplying
39 multiple versions to the utility will just sort them\.
44 A "version" is described by the \fBv2\.0\.0\fP specification found at
45 http://semver\.org/\|\.
47 A leading \fB"="\fP or \fB"v"\fP character is stripped off and ignored\.
50 A \fBversion range\fP is a set of \fBcomparators\fP which specify versions
51 that satisfy the range\.
53 A \fBcomparator\fP is composed of an \fBoperator\fP and a \fBversion\fP\|\. The set
54 of primitive \fBoperators\fP is:
59 \fB<=\fP Less than or equal to
63 \fB>=\fP Greater than or equal to
65 \fB=\fP Equal\. If no operator is specified, then equality is assumed,
66 so this operator is optional, but MAY be included\.
70 For example, the comparator \fB>=1\.2\.7\fP would match the versions
71 \fB1\.2\.7\fP, \fB1\.2\.8\fP, \fB2\.5\.3\fP, and \fB1\.3\.9\fP, but not the versions \fB1\.2\.6\fP
74 Comparators can be joined by whitespace to form a \fBcomparator set\fP,
75 which is satisfied by the \fBintersection\fR of all of the comparators
78 A range is composed of one or more comparator sets, joined by \fB||\fP\|\. A
79 version matches a range if and only if every comparator in at least
80 one of the \fB||\fP\-separated comparator sets is satisfied by the version\.
82 For example, the range \fB>=1\.2\.7 <1\.3\.0\fP would match the versions
83 \fB1\.2\.7\fP, \fB1\.2\.8\fP, and \fB1\.2\.99\fP, but not the versions \fB1\.2\.6\fP, \fB1\.3\.0\fP,
86 The range \fB1\.2\.7 || >=1\.2\.9 <2\.0\.0\fP would match the versions \fB1\.2\.7\fP,
87 \fB1\.2\.9\fP, and \fB1\.4\.6\fP, but not the versions \fB1\.2\.8\fP or \fB2\.0\.0\fP\|\.
90 If a version has a prerelease tag (for example, \fB1\.2\.3\-alpha\.3\fP) then
91 it will only be allowed to satisfy comparator sets if at least one
92 comparator with the same \fB[major, minor, patch]\fP tuple also has a
95 For example, the range \fB>1\.2\.3\-alpha\.3\fP would be allowed to match the
96 version \fB1\.2\.3\-alpha\.7\fP, but it would \fInot\fR be satisfied by
97 \fB3\.4\.5\-alpha\.9\fP, even though \fB3\.4\.5\-alpha\.9\fP is technically "greater
98 than" \fB1\.2\.3\-alpha\.3\fP according to the SemVer sort rules\. The version
99 range only accepts prerelease tags on the \fB1\.2\.3\fP version\. The
100 version \fB3\.4\.5\fP \fIwould\fR satisfy the range, because it does not have a
101 prerelease flag, and \fB3\.4\.5\fP is greater than \fB1\.2\.3\-alpha\.7\fP\|\.
103 The purpose for this behavior is twofold\. First, prerelease versions
104 frequently are updated very quickly, and contain many breaking changes
105 that are (by the author's design) not yet fit for public consumption\.
106 Therefore, by default, they are excluded from range matching
109 Second, a user who has opted into using a prerelease version has
110 clearly indicated the intent to use \fIthat specific\fR set of
111 alpha/beta/rc versions\. By including a prerelease tag in the range,
112 the user is indicating that they are aware of the risk\. However, it
113 is still not appropriate to assume that they have opted into taking a
114 similar risk on the \fInext\fR set of prerelease versions\.
115 .SS Prerelease Identifiers
117 The method \fB\|\.inc\fP takes an additional \fBidentifier\fP string argument that
118 will append the value of the string as a prerelease identifier:
122 > semver\.inc('1\.2\.3', 'prerelease', 'beta')
127 command\-line example:
131 $ semver 1\.2\.3 \-i prerelease \-\-preid beta
136 Which then can be used to increment further:
140 $ semver 1\.2\.4\-beta\.0 \-i prerelease
144 .SS Advanced Range Syntax
146 Advanced range syntax desugars to primitive comparators in
149 Advanced ranges may be combined in the same way as primitive
150 comparators using white space or \fB||\fP\|\.
151 .SS Hyphen Ranges \fBX\.Y\.Z \- A\.B\.C\fP
153 Specifies an inclusive set\.
156 \fB1\.2\.3 \- 2\.3\.4\fP := \fB>=1\.2\.3 <=2\.3\.4\fP
160 If a partial version is provided as the first version in the inclusive
161 range, then the missing pieces are replaced with zeroes\.
164 \fB1\.2 \- 2\.3\.4\fP := \fB>=1\.2\.0 <=2\.3\.4\fP
168 If a partial version is provided as the second version in the
169 inclusive range, then all versions that start with the supplied parts
170 of the tuple are accepted, but nothing that would be greater than the
171 provided tuple parts\.
174 \fB1\.2\.3 \- 2\.3\fP := \fB>=1\.2\.3 <2\.4\.0\fP
176 \fB1\.2\.3 \- 2\fP := \fB>=1\.2\.3 <3\.0\.0\fP
179 .SS X\-Ranges \fB1\.2\.x\fP \fB1\.X\fP \fB1\.2\.*\fP \fB*\fP
181 Any of \fBX\fP, \fBx\fP, or \fB*\fP may be used to "stand in" for one of the
182 numeric values in the \fB[major, minor, patch]\fP tuple\.
185 \fB*\fP := \fB>=0\.0\.0\fP (Any version satisfies)
187 \fB1\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP (Matching major version)
189 \fB1\.2\.x\fP := \fB>=1\.2\.0 <1\.3\.0\fP (Matching major and minor versions)
193 A partial version range is treated as an X\-Range, so the special
194 character is in fact optional\.
197 \fB""\fP (empty string) := \fB*\fP := \fB>=0\.0\.0\fP
199 \fB1\fP := \fB1\.x\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP
201 \fB1\.2\fP := \fB1\.2\.x\fP := \fB>=1\.2\.0 <1\.3\.0\fP
204 .SS Tilde Ranges \fB~1\.2\.3\fP \fB~1\.2\fP \fB~1\fP
206 Allows patch\-level changes if a minor version is specified on the
207 comparator\. Allows minor\-level changes if not\.
210 \fB~1\.2\.3\fP := \fB>=1\.2\.3 <1\.(2+1)\.0\fP := \fB>=1\.2\.3 <1\.3\.0\fP
212 \fB~1\.2\fP := \fB>=1\.2\.0 <1\.(2+1)\.0\fP := \fB>=1\.2\.0 <1\.3\.0\fP (Same as \fB1\.2\.x\fP)
214 \fB~1\fP := \fB>=1\.0\.0 <(1+1)\.0\.0\fP := \fB>=1\.0\.0 <2\.0\.0\fP (Same as \fB1\.x\fP)
216 \fB~0\.2\.3\fP := \fB>=0\.2\.3 <0\.(2+1)\.0\fP := \fB>=0\.2\.3 <0\.3\.0\fP
218 \fB~0\.2\fP := \fB>=0\.2\.0 <0\.(2+1)\.0\fP := \fB>=0\.2\.0 <0\.3\.0\fP (Same as \fB0\.2\.x\fP)
220 \fB~0\fP := \fB>=0\.0\.0 <(0+1)\.0\.0\fP := \fB>=0\.0\.0 <1\.0\.0\fP (Same as \fB0\.x\fP)
222 \fB~1\.2\.3\-beta\.2\fP := \fB>=1\.2\.3\-beta\.2 <1\.3\.0\fP Note that prereleases in
223 the \fB1\.2\.3\fP version will be allowed, if they are greater than or
224 equal to \fBbeta\.2\fP\|\. So, \fB1\.2\.3\-beta\.4\fP would be allowed, but
225 \fB1\.2\.4\-beta\.2\fP would not, because it is a prerelease of a
226 different \fB[major, minor, patch]\fP tuple\.
229 .SS Caret Ranges \fB^1\.2\.3\fP \fB^0\.2\.5\fP \fB^0\.0\.4\fP
231 Allows changes that do not modify the left\-most non\-zero digit in the
232 \fB[major, minor, patch]\fP tuple\. In other words, this allows patch and
233 minor updates for versions \fB1\.0\.0\fP and above, patch updates for
234 versions \fB0\.X >=0\.1\.0\fP, and \fIno\fR updates for versions \fB0\.0\.X\fP\|\.
236 Many authors treat a \fB0\.x\fP version as if the \fBx\fP were the major
237 "breaking\-change" indicator\.
239 Caret ranges are ideal when an author may make breaking changes
240 between \fB0\.2\.4\fP and \fB0\.3\.0\fP releases, which is a common practice\.
241 However, it presumes that there will \fInot\fR be breaking changes between
242 \fB0\.2\.4\fP and \fB0\.2\.5\fP\|\. It allows for changes that are presumed to be
243 additive (but non\-breaking), according to commonly observed practices\.
246 \fB^1\.2\.3\fP := \fB>=1\.2\.3 <2\.0\.0\fP
248 \fB^0\.2\.3\fP := \fB>=0\.2\.3 <0\.3\.0\fP
250 \fB^0\.0\.3\fP := \fB>=0\.0\.3 <0\.0\.4\fP
252 \fB^1\.2\.3\-beta\.2\fP := \fB>=1\.2\.3\-beta\.2 <2\.0\.0\fP Note that prereleases in
253 the \fB1\.2\.3\fP version will be allowed, if they are greater than or
254 equal to \fBbeta\.2\fP\|\. So, \fB1\.2\.3\-beta\.4\fP would be allowed, but
255 \fB1\.2\.4\-beta\.2\fP would not, because it is a prerelease of a
256 different \fB[major, minor, patch]\fP tuple\.
258 \fB^0\.0\.3\-beta\fP := \fB>=0\.0\.3\-beta <0\.0\.4\fP Note that prereleases in the
259 \fB0\.0\.3\fP version \fIonly\fR will be allowed, if they are greater than or
260 equal to \fBbeta\fP\|\. So, \fB0\.0\.3\-pr\.2\fP would be allowed\.
264 When parsing caret ranges, a missing \fBpatch\fP value desugars to the
265 number \fB0\fP, but will allow flexibility within that value, even if the
266 major and minor versions are both \fB0\fP\|\.
269 \fB^1\.2\.x\fP := \fB>=1\.2\.0 <2\.0\.0\fP
271 \fB^0\.0\.x\fP := \fB>=0\.0\.0 <0\.1\.0\fP
273 \fB^0\.0\fP := \fB>=0\.0\.0 <0\.1\.0\fP
277 A missing \fBminor\fP and \fBpatch\fP values will desugar to zero, but also
278 allow flexibility within those values, even if the major version is
282 \fB^1\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP
284 \fB^0\.x\fP := \fB>=0\.0\.0 <1\.0\.0\fP
289 Putting all this together, here is a Backus\-Naur grammar for ranges,
290 for the benefit of parser authors:
294 range\-set ::= range ( logical\-or range ) *
295 logical\-or ::= ( ' ' ) * '||' ( ' ' ) *
296 range ::= hyphen | simple ( ' ' simple ) * | ''
297 hyphen ::= partial ' \- ' partial
298 simple ::= primitive | partial | tilde | caret
299 primitive ::= ( '<' | '>' | '>=' | '<=' | '=' | ) partial
300 partial ::= xr ( '\.' xr ( '\.' xr qualifier ? )? )?
301 xr ::= 'x' | 'X' | '*' | nr
302 nr ::= '0' | ['1'\-'9']['0'\-'9']+
303 tilde ::= '~' partial
304 caret ::= '^' partial
305 qualifier ::= ( '\-' pre )? ( '+' build )?
308 parts ::= part ( '\.' part ) *
309 part ::= nr | [\-0\-9A\-Za\-z]+
314 All methods and classes take a final \fBloose\fP boolean argument that, if
315 true, will be more forgiving about not\-quite\-valid semver strings\.
316 The resulting output will always be 100% strict, of course\.
318 Strict\-mode Comparators and Ranges will be strict about the SemVer
319 strings that they parse\.
322 \fBvalid(v)\fP: Return the parsed version, or null if it's not valid\.
324 \fBinc(v, release)\fP: Return the version incremented by the release
325 type (\fBmajor\fP, \fBpremajor\fP, \fBminor\fP, \fBpreminor\fP, \fBpatch\fP,
326 \fBprepatch\fP, or \fBprerelease\fP), or null if it's not valid
329 \fBpremajor\fP in one call will bump the version up to the next major
330 version and down to a prerelease of that major version\.
331 \fBpreminor\fP, and \fBprepatch\fP work the same way\.
333 If called from a non\-prerelease version, the \fBprerelease\fP will work the
334 same as \fBprepatch\fP\|\. It increments the patch version, then makes a
335 prerelease\. If the input version is already a prerelease it simply
340 \fBmajor(v)\fP: Return the major version number\.
342 \fBminor(v)\fP: Return the minor version number\.
344 \fBpatch(v)\fP: Return the patch version number\.
350 \fBgt(v1, v2)\fP: \fBv1 > v2\fP
352 \fBgte(v1, v2)\fP: \fBv1 >= v2\fP
354 \fBlt(v1, v2)\fP: \fBv1 < v2\fP
356 \fBlte(v1, v2)\fP: \fBv1 <= v2\fP
358 \fBeq(v1, v2)\fP: \fBv1 == v2\fP This is true if they're logically equivalent,
359 even if they're not the exact same string\. You already know how to
362 \fBneq(v1, v2)\fP: \fBv1 != v2\fP The opposite of \fBeq\fP\|\.
364 \fBcmp(v1, comparator, v2)\fP: Pass in a comparison string, and it'll call
365 the corresponding function above\. \fB"==="\fP and \fB"!=="\fP do simple
366 string comparison, but are included for completeness\. Throws if an
367 invalid comparison string is provided\.
369 \fBcompare(v1, v2)\fP: Return \fB0\fP if \fBv1 == v2\fP, or \fB1\fP if \fBv1\fP is greater, or \fB\-1\fP if
370 \fBv2\fP is greater\. Sorts in ascending order if passed to \fBArray\.sort()\fP\|\.
372 \fBrcompare(v1, v2)\fP: The reverse of compare\. Sorts an array of versions
373 in descending order when passed to \fBArray\.sort()\fP\|\.
375 \fBdiff(v1, v2)\fP: Returns difference between two versions by the release type
376 (\fBmajor\fP, \fBpremajor\fP, \fBminor\fP, \fBpreminor\fP, \fBpatch\fP, \fBprepatch\fP, or \fBprerelease\fP),
377 or null if the versions are the same\.
383 \fBvalidRange(range)\fP: Return the valid range or null if it's not valid
385 \fBsatisfies(version, range)\fP: Return true if the version satisfies the
388 \fBmaxSatisfying(versions, range)\fP: Return the highest version in the list
389 that satisfies the range, or \fBnull\fP if none of them do\.
391 \fBgtr(version, range)\fP: Return \fBtrue\fP if version is greater than all the
392 versions possible in the range\.
394 \fBltr(version, range)\fP: Return \fBtrue\fP if version is less than all the
395 versions possible in the range\.
397 \fBoutside(version, range, hilo)\fP: Return true if the version is outside
398 the bounds of the range in either the high or low direction\. The
399 \fBhilo\fP argument must be either the string \fB\|'>'\fP or \fB\|'<'\fP\|\. (This is
400 the function called by \fBgtr\fP and \fBltr\fP\|\.)
404 Note that, since ranges may be non\-contiguous, a version might not be
405 greater than a range, less than a range, \fIor\fR satisfy a range! For
406 example, the range \fB1\.2 <1\.2\.9 || >2\.0\.0\fP would have a hole from \fB1\.2\.9\fP
407 until \fB2\.0\.0\fP, so the version \fB1\.2\.10\fP would not be greater than the
408 range (because \fB2\.0\.1\fP satisfies, which is higher), nor less than the
409 range (since \fB1\.2\.8\fP satisfies, which is lower), and it also does not
412 If you want to know if a version satisfies or does not satisfy a
413 range, use the \fBsatisfies(version, range)\fP function\.