| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510 | .TH "SEMVER" "7" "August 2021" "" "".SH "NAME"\fBsemver\fR \- The semantic versioner for npm.SH Install.P.RS 2.nfnpm install \-\-save semver.fi.RE.SH Usage.PAs a node module:.P.RS 2.nfconst semver = require('semver')semver\.valid('1\.2\.3') // '1\.2\.3'semver\.valid('a\.b\.c') // nullsemver\.clean('  =v1\.2\.3   ') // '1\.2\.3'semver\.satisfies('1\.2\.3', '1\.x || >=2\.5\.0 || 5\.0\.0 \- 7\.2\.3') // truesemver\.gt('1\.2\.3', '9\.8\.7') // falsesemver\.lt('1\.2\.3', '9\.8\.7') // truesemver\.minVersion('>=1\.0\.0') // '1\.0\.0'semver\.valid(semver\.coerce('v2')) // '2\.0\.0'semver\.valid(semver\.coerce('42\.6\.7\.9\.3\-alpha')) // '42\.6\.7'.fi.RE.PAs a command\-line utility:.P.RS 2.nf$ semver \-hA JavaScript implementation of the https://semver\.org/ specificationCopyright Isaac Z\. SchlueterUsage: semver [options] <version> [<version> [\.\.\.]]Prints valid versions sorted by SemVer precedenceOptions:\-r \-\-range <range>        Print versions that match the specified range\.\-i \-\-increment [<level>]        Increment a version by the specified level\.  Level can        be one of: major, minor, patch, premajor, preminor,        prepatch, or prerelease\.  Default level is 'patch'\.        Only one version may be specified\.\-\-preid <identifier>        Identifier to be used to prefix premajor, preminor,        prepatch or prerelease version increments\.\-l \-\-loose        Interpret versions and ranges loosely\-p \-\-include\-prerelease        Always include prerelease versions in range matching\-c \-\-coerce        Coerce a string into SemVer if possible        (does not imply \-\-loose)Program exits successfully if any valid version satisfiesall supplied ranges, and prints all satisfying versions\.If no satisfying versions are found, then exits failure\.Versions are printed in ascending order, so supplyingmultiple versions to the utility will just sort them\..fi.RE.SH Versions.PA "version" is described by the \fBv2\.0\.0\fP specification found athttps://semver\.org/\|\..PA leading \fB"="\fP or \fB"v"\fP character is stripped off and ignored\..SH Ranges.PA \fBversion range\fP is a set of \fBcomparators\fP which specify versionsthat satisfy the range\..PA \fBcomparator\fP is composed of an \fBoperator\fP and a \fBversion\fP\|\.  The setof primitive \fBoperators\fP is:.RS 0.IP \(bu 2\fB<\fP Less than.IP \(bu 2\fB<=\fP Less than or equal to.IP \(bu 2\fB>\fP Greater than.IP \(bu 2\fB>=\fP Greater than or equal to.IP \(bu 2\fB=\fP Equal\.  If no operator is specified, then equality is assumed,so this operator is optional, but MAY be included\..RE.PFor example, the comparator \fB>=1\.2\.7\fP would match the versions\fB1\.2\.7\fP, \fB1\.2\.8\fP, \fB2\.5\.3\fP, and \fB1\.3\.9\fP, but not the versions \fB1\.2\.6\fPor \fB1\.1\.0\fP\|\..PComparators can be joined by whitespace to form a \fBcomparator set\fP,which is satisfied by the \fBintersection\fR of all of the comparatorsit includes\..PA range is composed of one or more comparator sets, joined by \fB||\fP\|\.  Aversion matches a range if and only if every comparator in at leastone of the \fB||\fP\-separated comparator sets is satisfied by the version\..PFor example, the range \fB>=1\.2\.7 <1\.3\.0\fP would match the versions\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,or \fB1\.1\.0\fP\|\..PThe range \fB1\.2\.7 || >=1\.2\.9 <2\.0\.0\fP would match the versions \fB1\.2\.7\fP,\fB1\.2\.9\fP, and \fB1\.4\.6\fP, but not the versions \fB1\.2\.8\fP or \fB2\.0\.0\fP\|\..SS Prerelease Tags.PIf a version has a prerelease tag (for example, \fB1\.2\.3\-alpha\.3\fP) thenit will only be allowed to satisfy comparator sets if at least onecomparator with the same \fB[major, minor, patch]\fP tuple also has aprerelease tag\..PFor example, the range \fB>1\.2\.3\-alpha\.3\fP would be allowed to match theversion \fB1\.2\.3\-alpha\.7\fP, but it would \fInot\fR be satisfied by\fB3\.4\.5\-alpha\.9\fP, even though \fB3\.4\.5\-alpha\.9\fP is technically "greaterthan" \fB1\.2\.3\-alpha\.3\fP according to the SemVer sort rules\.  The versionrange only accepts prerelease tags on the \fB1\.2\.3\fP version\.  Theversion \fB3\.4\.5\fP \fIwould\fR satisfy the range, because it does not have aprerelease flag, and \fB3\.4\.5\fP is greater than \fB1\.2\.3\-alpha\.7\fP\|\..PThe purpose for this behavior is twofold\.  First, prerelease versionsfrequently are updated very quickly, and contain many breaking changesthat are (by the author's design) not yet fit for public consumption\.Therefore, by default, they are excluded from range matchingsemantics\..PSecond, a user who has opted into using a prerelease version hasclearly indicated the intent to use \fIthat specific\fR set ofalpha/beta/rc versions\.  By including a prerelease tag in the range,the user is indicating that they are aware of the risk\.  However, itis still not appropriate to assume that they have opted into taking asimilar risk on the \fInext\fR set of prerelease versions\..PNote that this behavior can be suppressed (treating all prereleaseversions as if they were normal versions, for the purpose of rangematching) by setting the \fBincludePrerelease\fP flag on the optionsobject to anyfunctions \fIhttps://github\.com/npm/node\-semver#functions\fR that dorange matching\..SS Prerelease Identifiers.PThe method \fB\|\.inc\fP takes an additional \fBidentifier\fP string argument thatwill append the value of the string as a prerelease identifier:.P.RS 2.nfsemver\.inc('1\.2\.3', 'prerelease', 'beta')// '1\.2\.4\-beta\.0'.fi.RE.Pcommand\-line example:.P.RS 2.nf$ semver 1\.2\.3 \-i prerelease \-\-preid beta1\.2\.4\-beta\.0.fi.RE.PWhich then can be used to increment further:.P.RS 2.nf$ semver 1\.2\.4\-beta\.0 \-i prerelease1\.2\.4\-beta\.1.fi.RE.SS Advanced Range Syntax.PAdvanced range syntax desugars to primitive comparators indeterministic ways\..PAdvanced ranges may be combined in the same way as primitivecomparators using white space or \fB||\fP\|\..SS Hyphen Ranges \fBX\.Y\.Z \- A\.B\.C\fP.PSpecifies an inclusive set\..RS 0.IP \(bu 2\fB1\.2\.3 \- 2\.3\.4\fP := \fB>=1\.2\.3 <=2\.3\.4\fP.RE.PIf a partial version is provided as the first version in the inclusiverange, then the missing pieces are replaced with zeroes\..RS 0.IP \(bu 2\fB1\.2 \- 2\.3\.4\fP := \fB>=1\.2\.0 <=2\.3\.4\fP.RE.PIf a partial version is provided as the second version in theinclusive range, then all versions that start with the supplied partsof the tuple are accepted, but nothing that would be greater than theprovided tuple parts\..RS 0.IP \(bu 2\fB1\.2\.3 \- 2\.3\fP := \fB>=1\.2\.3 <2\.4\.0\fP.IP \(bu 2\fB1\.2\.3 \- 2\fP := \fB>=1\.2\.3 <3\.0\.0\fP.RE.SS X\-Ranges \fB1\.2\.x\fP \fB1\.X\fP \fB1\.2\.*\fP \fB*\fP.PAny of \fBX\fP, \fBx\fP, or \fB*\fP may be used to "stand in" for one of thenumeric values in the \fB[major, minor, patch]\fP tuple\..RS 0.IP \(bu 2\fB*\fP := \fB>=0\.0\.0\fP (Any version satisfies).IP \(bu 2\fB1\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP (Matching major version).IP \(bu 2\fB1\.2\.x\fP := \fB>=1\.2\.0 <1\.3\.0\fP (Matching major and minor versions).RE.PA partial version range is treated as an X\-Range, so the specialcharacter is in fact optional\..RS 0.IP \(bu 2\fB""\fP (empty string) := \fB*\fP := \fB>=0\.0\.0\fP.IP \(bu 2\fB1\fP := \fB1\.x\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP.IP \(bu 2\fB1\.2\fP := \fB1\.2\.x\fP := \fB>=1\.2\.0 <1\.3\.0\fP.RE.SS Tilde Ranges \fB~1\.2\.3\fP \fB~1\.2\fP \fB~1\fP.PAllows patch\-level changes if a minor version is specified on thecomparator\.  Allows minor\-level changes if not\..RS 0.IP \(bu 2\fB~1\.2\.3\fP := \fB>=1\.2\.3 <1\.(2+1)\.0\fP := \fB>=1\.2\.3 <1\.3\.0\fP.IP \(bu 2\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).IP \(bu 2\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).IP \(bu 2\fB~0\.2\.3\fP := \fB>=0\.2\.3 <0\.(2+1)\.0\fP := \fB>=0\.2\.3 <0\.3\.0\fP.IP \(bu 2\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).IP \(bu 2\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).IP \(bu 2\fB~1\.2\.3\-beta\.2\fP := \fB>=1\.2\.3\-beta\.2 <1\.3\.0\fP Note that prereleases inthe \fB1\.2\.3\fP version will be allowed, if they are greater than orequal to \fBbeta\.2\fP\|\.  So, \fB1\.2\.3\-beta\.4\fP would be allowed, but\fB1\.2\.4\-beta\.2\fP would not, because it is a prerelease of adifferent \fB[major, minor, patch]\fP tuple\..RE.SS Caret Ranges \fB^1\.2\.3\fP \fB^0\.2\.5\fP \fB^0\.0\.4\fP.PAllows changes that do not modify the left\-most non\-zero digit in the\fB[major, minor, patch]\fP tuple\.  In other words, this allows patch andminor updates for versions \fB1\.0\.0\fP and above, patch updates forversions \fB0\.X >=0\.1\.0\fP, and \fIno\fR updates for versions \fB0\.0\.X\fP\|\..PMany authors treat a \fB0\.x\fP version as if the \fBx\fP were the major"breaking\-change" indicator\..PCaret ranges are ideal when an author may make breaking changesbetween \fB0\.2\.4\fP and \fB0\.3\.0\fP releases, which is a common practice\.However, it presumes that there will \fInot\fR be breaking changes between\fB0\.2\.4\fP and \fB0\.2\.5\fP\|\.  It allows for changes that are presumed to beadditive (but non\-breaking), according to commonly observed practices\..RS 0.IP \(bu 2\fB^1\.2\.3\fP := \fB>=1\.2\.3 <2\.0\.0\fP.IP \(bu 2\fB^0\.2\.3\fP := \fB>=0\.2\.3 <0\.3\.0\fP.IP \(bu 2\fB^0\.0\.3\fP := \fB>=0\.0\.3 <0\.0\.4\fP.IP \(bu 2\fB^1\.2\.3\-beta\.2\fP := \fB>=1\.2\.3\-beta\.2 <2\.0\.0\fP Note that prereleases inthe \fB1\.2\.3\fP version will be allowed, if they are greater than orequal to \fBbeta\.2\fP\|\.  So, \fB1\.2\.3\-beta\.4\fP would be allowed, but\fB1\.2\.4\-beta\.2\fP would not, because it is a prerelease of adifferent \fB[major, minor, patch]\fP tuple\..IP \(bu 2\fB^0\.0\.3\-beta\fP := \fB>=0\.0\.3\-beta <0\.0\.4\fP  Note that prereleases in the\fB0\.0\.3\fP version \fIonly\fR will be allowed, if they are greater than orequal to \fBbeta\fP\|\.  So, \fB0\.0\.3\-pr\.2\fP would be allowed\..RE.PWhen parsing caret ranges, a missing \fBpatch\fP value desugars to thenumber \fB0\fP, but will allow flexibility within that value, even if themajor and minor versions are both \fB0\fP\|\..RS 0.IP \(bu 2\fB^1\.2\.x\fP := \fB>=1\.2\.0 <2\.0\.0\fP.IP \(bu 2\fB^0\.0\.x\fP := \fB>=0\.0\.0 <0\.1\.0\fP.IP \(bu 2\fB^0\.0\fP := \fB>=0\.0\.0 <0\.1\.0\fP.RE.PA missing \fBminor\fP and \fBpatch\fP values will desugar to zero, but alsoallow flexibility within those values, even if the major version iszero\..RS 0.IP \(bu 2\fB^1\.x\fP := \fB>=1\.0\.0 <2\.0\.0\fP.IP \(bu 2\fB^0\.x\fP := \fB>=0\.0\.0 <1\.0\.0\fP.RE.SS Range Grammar.PPutting all this together, here is a Backus\-Naur grammar for ranges,for the benefit of parser authors:.P.RS 2.nfrange\-set  ::= range ( logical\-or range ) *logical\-or ::= ( ' ' ) * '||' ( ' ' ) *range      ::= hyphen | simple ( ' ' simple ) * | ''hyphen     ::= partial ' \- ' partialsimple     ::= primitive | partial | tilde | caretprimitive  ::= ( '<' | '>' | '>=' | '<=' | '=' ) partialpartial    ::= xr ( '\.' xr ( '\.' xr qualifier ? )? )?xr         ::= 'x' | 'X' | '*' | nrnr         ::= '0' | ['1'\-'9'] ( ['0'\-'9'] ) *tilde      ::= '~' partialcaret      ::= '^' partialqualifier  ::= ( '\-' pre )? ( '+' build )?pre        ::= partsbuild      ::= partsparts      ::= part ( '\.' part ) *part       ::= nr | [\-0\-9A\-Za\-z]+.fi.RE.SH Functions.PAll methods and classes take a final \fBoptions\fP object argument\.  Alloptions in this object are \fBfalse\fP by default\.  The options supportedare:.RS 0.IP \(bu 2\fBloose\fP  Be more forgiving about not\-quite\-valid semver strings\.(Any resulting output will always be 100% strict compliant, ofcourse\.)  For backwards compatibility reasons, if the \fBoptions\fPargument is a boolean value instead of an object, it is interpretedto be the \fBloose\fP param\..IP \(bu 2\fBincludePrerelease\fP  Set to suppress the defaultbehavior \fIhttps://github\.com/npm/node\-semver#prerelease\-tags\fR ofexcluding prerelease tagged versions from ranges unless they areexplicitly opted into\..RE.PStrict\-mode Comparators and Ranges will be strict about the SemVerstrings that they parse\..RS 0.IP \(bu 2\fBvalid(v)\fP: Return the parsed version, or null if it's not valid\..IP \(bu 2\fBinc(v, release)\fP: Return the version incremented by the releasetype (\fBmajor\fP,   \fBpremajor\fP, \fBminor\fP, \fBpreminor\fP, \fBpatch\fP,\fBprepatch\fP, or \fBprerelease\fP), or null if it's not valid.RS.IP \(bu 2\fBpremajor\fP in one call will bump the version up to the next majorversion and down to a prerelease of that major version\.\fBpreminor\fP, and \fBprepatch\fP work the same way\..IP \(bu 2If called from a non\-prerelease version, the \fBprerelease\fP will work thesame as \fBprepatch\fP\|\. It increments the patch version, then makes aprerelease\. If the input version is already a prerelease it simplyincrements it\..RE.IP \(bu 2\fBprerelease(v)\fP: Returns an array of prerelease components, or nullif none exist\. Example: \fBprerelease('1\.2\.3\-alpha\.1') \-> ['alpha', 1]\fP.IP \(bu 2\fBmajor(v)\fP: Return the major version number\..IP \(bu 2\fBminor(v)\fP: Return the minor version number\..IP \(bu 2\fBpatch(v)\fP: Return the patch version number\..IP \(bu 2\fBintersects(r1, r2, loose)\fP: Return true if the two supplied rangesor comparators intersect\..IP \(bu 2\fBparse(v)\fP: Attempt to parse a string as a semantic version, returning eithera \fBSemVer\fP object or \fBnull\fP\|\..RE.SS Comparison.RS 0.IP \(bu 2\fBgt(v1, v2)\fP: \fBv1 > v2\fP.IP \(bu 2\fBgte(v1, v2)\fP: \fBv1 >= v2\fP.IP \(bu 2\fBlt(v1, v2)\fP: \fBv1 < v2\fP.IP \(bu 2\fBlte(v1, v2)\fP: \fBv1 <= v2\fP.IP \(bu 2\fBeq(v1, v2)\fP: \fBv1 == v2\fP This is true if they're logically equivalent,even if they're not the exact same string\.  You already know how tocompare strings\..IP \(bu 2\fBneq(v1, v2)\fP: \fBv1 != v2\fP The opposite of \fBeq\fP\|\..IP \(bu 2\fBcmp(v1, comparator, v2)\fP: Pass in a comparison string, and it'll callthe corresponding function above\.  \fB"==="\fP and \fB"!=="\fP do simplestring comparison, but are included for completeness\.  Throws if aninvalid comparison string is provided\..IP \(bu 2\fBcompare(v1, v2)\fP: Return \fB0\fP if \fBv1 == v2\fP, or \fB1\fP if \fBv1\fP is greater, or \fB\-1\fP if\fBv2\fP is greater\.  Sorts in ascending order if passed to \fBArray\.sort()\fP\|\..IP \(bu 2\fBrcompare(v1, v2)\fP: The reverse of compare\.  Sorts an array of versionsin descending order when passed to \fBArray\.sort()\fP\|\..IP \(bu 2\fBdiff(v1, v2)\fP: Returns difference between two versions by the release type(\fBmajor\fP, \fBpremajor\fP, \fBminor\fP, \fBpreminor\fP, \fBpatch\fP, \fBprepatch\fP, or \fBprerelease\fP),or null if the versions are the same\..RE.SS Comparators.RS 0.IP \(bu 2\fBintersects(comparator)\fP: Return true if the comparators intersect.RE.SS Ranges.RS 0.IP \(bu 2\fBvalidRange(range)\fP: Return the valid range or null if it's not valid.IP \(bu 2\fBsatisfies(version, range)\fP: Return true if the version satisfies therange\..IP \(bu 2\fBmaxSatisfying(versions, range)\fP: Return the highest version in the listthat satisfies the range, or \fBnull\fP if none of them do\..IP \(bu 2\fBminSatisfying(versions, range)\fP: Return the lowest version in the listthat satisfies the range, or \fBnull\fP if none of them do\..IP \(bu 2\fBminVersion(range)\fP: Return the lowest version that can possibly matchthe given range\..IP \(bu 2\fBgtr(version, range)\fP: Return \fBtrue\fP if version is greater than all theversions possible in the range\..IP \(bu 2\fBltr(version, range)\fP: Return \fBtrue\fP if version is less than all theversions possible in the range\..IP \(bu 2\fBoutside(version, range, hilo)\fP: Return true if the version is outsidethe bounds of the range in either the high or low direction\.  The\fBhilo\fP argument must be either the string \fB\|'>'\fP or \fB\|'<'\fP\|\.  (This isthe function called by \fBgtr\fP and \fBltr\fP\|\.).IP \(bu 2\fBintersects(range)\fP: Return true if any of the ranges comparators intersect.RE.PNote that, since ranges may be non\-contiguous, a version might not begreater than a range, less than a range, \fIor\fR satisfy a range!  Forexample, the range \fB1\.2 <1\.2\.9 || >2\.0\.0\fP would have a hole from \fB1\.2\.9\fPuntil \fB2\.0\.0\fP, so the version \fB1\.2\.10\fP would not be greater than therange (because \fB2\.0\.1\fP satisfies, which is higher), nor less than therange (since \fB1\.2\.8\fP satisfies, which is lower), and it also does notsatisfy the range\..PIf you want to know if a version satisfies or does not satisfy arange, use the \fBsatisfies(version, range)\fP function\..SS Coercion.RS 0.IP \(bu 2\fBcoerce(version)\fP: Coerces a string to semver if possible.RE.PThis aims to provide a very forgiving translation of a non\-semver string tosemver\. It looks for the first digit in a string, and consumes allremaining characters which satisfy at least a partial semver (e\.g\., \fB1\fP,\fB1\.2\fP, \fB1\.2\.3\fP) up to the max permitted length (256 characters)\.  Longerversions are simply truncated (\fB4\.6\.3\.9\.2\-alpha2\fP becomes \fB4\.6\.3\fP)\.  Allsurrounding text is simply ignored (\fBv3\.4 replaces v3\.3\.1\fP becomes\fB3\.4\.0\fP)\.  Only text which lacks digits will fail coercion (\fBversion one\fPis not valid)\.  The maximum  length for any semver component considered forcoercion is 16 characters; longer components will be ignored(\fB10000000000000000\.4\.7\.4\fP becomes \fB4\.7\.4\fP)\.  The maximum value for anysemver component is \fBNumber\.MAX_SAFE_INTEGER || (2**53 \- 1)\fP; higher valuecomponents are invalid (\fB9999999999999999\.4\.7\.4\fP is likely invalid)\.
 |