.TH "SEMVER" "1" "August 2023" "7.5.4" .SH "NAME" \fBsemver\fR \- The semantic versioner for npm .SH Install .RS 2 .nf npm install semver .fi .RE .SH Usage .P As a node module: .RS 2 .nf const semver = require('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 semver\.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 .P You can also just load the module for the function that you care about, if .br you'd like to minimize your footprint\. .RS 2 .nf // load the whole API at once in a single object const semver = require('semver') // or just load the bits you need // all of them listed here, just pick and choose what you want // classes const SemVer = require('semver/classes/semver') const Comparator = require('semver/classes/comparator') const Range = require('semver/classes/range') // functions for working with versions const semverParse = require('semver/functions/parse') const semverValid = require('semver/functions/valid') const semverClean = require('semver/functions/clean') const semverInc = require('semver/functions/inc') const semverDiff = require('semver/functions/diff') const semverMajor = require('semver/functions/major') const semverMinor = require('semver/functions/minor') const semverPatch = require('semver/functions/patch') const semverPrerelease = require('semver/functions/prerelease') const semverCompare = require('semver/functions/compare') const semverRcompare = require('semver/functions/rcompare') const semverCompareLoose = require('semver/functions/compare\-loose') const semverCompareBuild = require('semver/functions/compare\-build') const semverSort = require('semver/functions/sort') const semverRsort = require('semver/functions/rsort') // low\-level comparators between versions const semverGt = require('semver/functions/gt') const semverLt = require('semver/functions/lt') const semverEq = require('semver/functions/eq') const semverNeq = require('semver/functions/neq') const semverGte = require('semver/functions/gte') const semverLte = require('semver/functions/lte') const semverCmp = require('semver/functions/cmp') const semverCoerce = require('semver/functions/coerce') // working with ranges const semverSatisfies = require('semver/functions/satisfies') const semverMaxSatisfying = require('semver/ranges/max\-satisfying') const semverMinSatisfying = require('semver/ranges/min\-satisfying') const semverToComparators = require('semver/ranges/to\-comparators') const semverMinVersion = require('semver/ranges/min\-version') const semverValidRange = require('semver/ranges/valid') const semverOutside = require('semver/ranges/outside') const semverGtr = require('semver/ranges/gtr') const semverLtr = require('semver/ranges/ltr') const semverIntersects = require('semver/ranges/intersects') const simplifyRange = require('semver/ranges/simplify') const rangeSubset = require('semver/ranges/subset') .fi .RE .P As a command\-line utility: .RS 2 .nf $ semver \-h A JavaScript implementation of the https://semver\.org/ specification Copyright Isaac Z\. Schlueter Usage: semver [options] [ [\.\.\.]] Prints valid versions sorted by SemVer precedence Options: \-r \-\-range Print versions that match the specified range\. \-i \-\-increment [] 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 to be used to prefix premajor, preminor, prepatch or prerelease version increments\. \-l \-\-loose Interpret versions and ranges loosely \-n <0|1> This is the base to be used for the prerelease identifier\. \-p \-\-include\-prerelease Always include prerelease versions in range matching \-c \-\-coerce Coerce a string into SemVer if possible (does not imply \-\-loose) \-\-rtl Coerce version strings right to left \-\-ltr Coerce version strings left to right (default) Program exits successfully if any valid version satisfies all supplied ranges, and prints all satisfying versions\. If no satisfying versions are found, then exits failure\. Versions are printed in ascending order, so supplying multiple versions to the utility will just sort them\. .fi .RE .SH Versions .P A "version" is described by the \fBv2\.0\.0\fP specification found at .br https://semver.org/ .P A leading \fB"="\fP or \fB"v"\fP character is stripped off and ignored\. .SH Ranges .P A \fBversion range\fP is a set of \fBcomparators\fP which specify versions .br that satisfy the range\. .P A \fBcomparator\fP is composed of an \fBoperator\fP and a \fBversion\fP\|\. The set .br of primitive \fBoperators\fP is: .RS 1 .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, .br so this operator is optional, but MAY be included\. .RE .P For example, the comparator \fB>=1\.2\.7\fP would match the versions .br \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 .br or \fB1\.1\.0\fP\|\. The comparator \fB>1\fP is equivalent to \fB>=2\.0\.0\fP and .br would match the versions \fB2\.0\.0\fP and \fB3\.1\.0\fP, but not the versions .br \fB1\.0\.1\fP or \fB1\.1\.0\fP\|\. .P Comparators can be joined by whitespace to form a \fBcomparator set\fP, .br which is satisfied by the \fBintersection\fR of all of the comparators .br it includes\. .P A range is composed of one or more comparator sets, joined by \fB||\fP\|\. A .br version matches a range if and only if every comparator in at least .br one of the \fB||\fP\-separated comparator sets is satisfied by the version\. .P For example, the range \fB>=1\.2\.7 <1\.3\.0\fP would match the versions .br \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, .br or \fB1\.1\.0\fP\|\. .P The range \fB1\.2\.7 || >=1\.2\.9 <2\.0\.0\fP would match the versions \fB1\.2\.7\fP, .br \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 .P If a version has a prerelease tag (for example, \fB1\.2\.3\-alpha\.3\fP) then .br it will only be allowed to satisfy comparator sets if at least one .br comparator with the same \fB[major, minor, patch]\fP tuple also has a .br prerelease tag\. .P For example, the range \fB>1\.2\.3\-alpha\.3\fP would be allowed to match the .br version \fB1\.2\.3\-alpha\.7\fP, but it would \fInot\fR be satisfied by .br \fB3\.4\.5\-alpha\.9\fP, even though \fB3\.4\.5\-alpha\.9\fP is technically "greater .br than" \fB1\.2\.3\-alpha\.3\fP according to the SemVer sort rules\. The version .br range only accepts prerelease tags on the \fB1\.2\.3\fP version\. The .br version \fB3\.4\.5\fP \fIwould\fR satisfy the range, because it does not have a .br prerelease flag, and \fB3\.4\.5\fP is greater than \fB1\.2\.3\-alpha\.7\fP\|\. .P The purpose for this behavior is twofold\. First, prerelease versions .br frequently are updated very quickly, and contain many breaking changes .br that are (by the author's design) not yet fit for public consumption\. .br Therefore, by default, they are excluded from range matching .br semantics\. .P Second, a user who has opted into using a prerelease version has .br clearly indicated the intent to use \fIthat specific\fR set of .br alpha/beta/rc versions\. By including a prerelease tag in the range, .br the user is indicating that they are aware of the risk\. However, it .br is still not appropriate to assume that they have opted into taking a .br similar risk on the \fInext\fR set of prerelease versions\. .P Note that this behavior can be suppressed (treating all prerelease .br versions as if they were normal versions, for the purpose of range .br matching) by setting the \fBincludePrerelease\fP flag on the options .br object to any .br .UR https://github.com/npm/node-semver#functions .I functions .UE that do .br range matching\. .SS Prerelease Identifiers .P The method \fB\|\.inc\fP takes an additional \fBidentifier\fP string argument that .br will append the value of the string as a prerelease identifier: .RS 2 .nf semver\.inc('1\.2\.3', 'prerelease', 'beta') // '1\.2\.4\-beta\.0' .fi .RE .P command\-line example: .RS 2 .nf $ semver 1\.2\.3 \-i prerelease \-\-preid beta 1\.2\.4\-beta\.0 .fi .RE .P Which then can be used to increment further: .RS 2 .nf $ semver 1\.2\.4\-beta\.0 \-i prerelease 1\.2\.4\-beta\.1 .fi .RE .SS Prerelease Identifier Base .P The method \fB\|\.inc\fP takes an optional parameter 'identifierBase' string .br that will let you let your prerelease number as zero\-based or one\-based\. .br Set to \fBfalse\fP to omit the prerelease number altogether\. .br If you do not specify this parameter, it will default to zero\-based\. .RS 2 .nf semver\.inc('1\.2\.3', 'prerelease', 'beta', '1') // '1\.2\.4\-beta\.1' .fi .RE .RS 2 .nf semver\.inc('1\.2\.3', 'prerelease', 'beta', false) // '1\.2\.4\-beta' .fi .RE .P command\-line example: .RS 2 .nf $ semver 1\.2\.3 \-i prerelease \-\-preid beta \-n 1 1\.2\.4\-beta\.1 .fi .RE .RS 2 .nf $ semver 1\.2\.3 \-i prerelease \-\-preid beta \-n false 1\.2\.4\-beta .fi .RE .SS Advanced Range Syntax .P Advanced range syntax desugars to primitive comparators in .br deterministic ways\. .P Advanced ranges may be combined in the same way as primitive .br comparators using white space or \fB||\fP\|\. .SS Hyphen Ranges \fBX\.Y\.Z \- A\.B\.C\fP .P Specifies an inclusive set\. .RS 1 .IP \(bu 2 \fB1\.2\.3 \- 2\.3\.4\fP := \fB>=1\.2\.3 <=2\.3\.4\fP .RE .P If a partial version is provided as the first version in the inclusive .br range, then the missing pieces are replaced with zeroes\. .RS 1 .IP \(bu 2 \fB1\.2 \- 2\.3\.4\fP := \fB>=1\.2\.0 <=2\.3\.4\fP .RE .P If a partial version is provided as the second version in the .br inclusive range, then all versions that start with the supplied parts .br of the tuple are accepted, but nothing that would be greater than the .br provided tuple parts\. .RS 1 .IP \(bu 2 \fB1\.2\.3 \- 2\.3\fP := \fB>=1\.2\.3 <2\.4\.0\-0\fP .IP \(bu 2 \fB1\.2\.3 \- 2\fP := \fB>=1\.2\.3 <3\.0\.0\-0\fP .RE .SS X\-Ranges \fB1\.2\.x\fP \fB1\.X\fP \fB1\.2\.*\fP \fB*\fP .P Any of \fBX\fP, \fBx\fP, or \fB*\fP may be used to "stand in" for one of the .br numeric values in the \fB[major, minor, patch]\fP tuple\. .RS 1 .IP \(bu 2 \fB*\fP := \fB>=0\.0\.0\fP (Any non\-prerelease version satisfies, unless .br \fBincludePrerelease\fP is specified, in which case any version at all .br satisfies) .IP \(bu 2 \fB1\.x\fP := \fB>=1\.0\.0 <2\.0\.0\-0\fP (Matching major version) .IP \(bu 2 \fB1\.2\.x\fP := \fB>=1\.2\.0 <1\.3\.0\-0\fP (Matching major and minor versions) .RE .P A partial version range is treated as an X\-Range, so the special .br character is in fact optional\. .RS 1 .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\-0\fP .IP \(bu 2 \fB1\.2\fP := \fB1\.2\.x\fP := \fB>=1\.2\.0 <1\.3\.0\-0\fP .RE .SS Tilde Ranges \fB~1\.2\.3\fP \fB~1\.2\fP \fB~1\fP .P Allows patch\-level changes if a minor version is specified on the .br comparator\. Allows minor\-level changes if not\. .RS 1 .IP \(bu 2 \fB~1\.2\.3\fP := \fB>=1\.2\.3 <1\.(2+1)\.0\fP := \fB>=1\.2\.3 <1\.3\.0\-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\-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\-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\-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\-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\-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\-0\fP Note that prereleases in .br the \fB1\.2\.3\fP version will be allowed, if they are greater than or .br equal to \fBbeta\.2\fP\|\. So, \fB1\.2\.3\-beta\.4\fP would be allowed, but .br \fB1\.2\.4\-beta\.2\fP would not, because it is a prerelease of a .br different \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 .P Allows changes that do not modify the left\-most non\-zero element in the .br \fB[major, minor, patch]\fP tuple\. In other words, this allows patch and .br minor updates for versions \fB1\.0\.0\fP and above, patch updates for .br versions \fB0\.X >=0\.1\.0\fP, and \fIno\fR updates for versions \fB0\.0\.X\fP\|\. .P Many authors treat a \fB0\.x\fP version as if the \fBx\fP were the major .br "breaking\-change" indicator\. .P Caret ranges are ideal when an author may make breaking changes .br between \fB0\.2\.4\fP and \fB0\.3\.0\fP releases, which is a common practice\. .br However, it presumes that there will \fInot\fR be breaking changes between .br \fB0\.2\.4\fP and \fB0\.2\.5\fP\|\. It allows for changes that are presumed to be .br additive (but non\-breaking), according to commonly observed practices\. .RS 1 .IP \(bu 2 \fB^1\.2\.3\fP := \fB>=1\.2\.3 <2\.0\.0\-0\fP .IP \(bu 2 \fB^0\.2\.3\fP := \fB>=0\.2\.3 <0\.3\.0\-0\fP .IP \(bu 2 \fB^0\.0\.3\fP := \fB>=0\.0\.3 <0\.0\.4\-0\fP .IP \(bu 2 \fB^1\.2\.3\-beta\.2\fP := \fB>=1\.2\.3\-beta\.2 <2\.0\.0\-0\fP Note that prereleases in .br the \fB1\.2\.3\fP version will be allowed, if they are greater than or .br equal to \fBbeta\.2\fP\|\. So, \fB1\.2\.3\-beta\.4\fP would be allowed, but .br \fB1\.2\.4\-beta\.2\fP would not, because it is a prerelease of a .br different \fB[major, minor, patch]\fP tuple\. .IP \(bu 2 \fB^0\.0\.3\-beta\fP := \fB>=0\.0\.3\-beta <0\.0\.4\-0\fP Note that prereleases in the .br \fB0\.0\.3\fP version \fIonly\fR will be allowed, if they are greater than or .br equal to \fBbeta\fP\|\. So, \fB0\.0\.3\-pr\.2\fP would be allowed\. .RE .P When parsing caret ranges, a missing \fBpatch\fP value desugars to the .br number \fB0\fP, but will allow flexibility within that value, even if the .br major and minor versions are both \fB0\fP\|\. .RS 1 .IP \(bu 2 \fB^1\.2\.x\fP := \fB>=1\.2\.0 <2\.0\.0\-0\fP .IP \(bu 2 \fB^0\.0\.x\fP := \fB>=0\.0\.0 <0\.1\.0\-0\fP .IP \(bu 2 \fB^0\.0\fP := \fB>=0\.0\.0 <0\.1\.0\-0\fP .RE .P A missing \fBminor\fP and \fBpatch\fP values will desugar to zero, but also .br allow flexibility within those values, even if the major version is .br zero\. .RS 1 .IP \(bu 2 \fB^1\.x\fP := \fB>=1\.0\.0 <2\.0\.0\-0\fP .IP \(bu 2 \fB^0\.x\fP := \fB>=0\.0\.0 <1\.0\.0\-0\fP .RE .SS Range Grammar .P Putting all this together, here is a Backus\-Naur grammar for ranges, .br for the benefit of parser authors: .RS 2 .nf range\-set ::= range ( logical\-or range ) * logical\-or ::= ( ' ' ) * '||' ( ' ' ) * range ::= hyphen | simple ( ' ' simple ) * | '' hyphen ::= partial ' \- ' partial simple ::= primitive | partial | tilde | caret primitive ::= ( '<' | '>' | '>=' | '<=' | '=' ) partial partial ::= xr ( '\.' xr ( '\.' xr qualifier ? )? )? xr ::= 'x' | 'X' | '*' | nr nr ::= '0' | ['1'\-'9'] ( ['0'\-'9'] ) * tilde ::= '~' partial caret ::= '^' partial qualifier ::= ( '\-' pre )? ( '+' build )? pre ::= parts build ::= parts parts ::= part ( '\.' part ) * part ::= nr | [\-0\-9A\-Za\-z]+ .fi .RE .SH Functions .P All methods and classes take a final \fBoptions\fP object argument\. All .br options in this object are \fBfalse\fP by default\. The options supported .br are: .RS 1 .IP \(bu 2 \fBloose\fP Be more forgiving about not\-quite\-valid semver strings\. .br (Any resulting output will always be 100% strict compliant, of .br course\.) For backwards compatibility reasons, if the \fBoptions\fP .br argument is a boolean value instead of an object, it is interpreted .br to be the \fBloose\fP param\. .IP \(bu 2 \fBincludePrerelease\fP Set to suppress the .UR https://github.com/npm/node-semver#prerelease-tags .I default behavior .UE of .br excluding prerelease tagged versions from ranges unless they are .br explicitly opted into\. .RE .P Strict\-mode Comparators and Ranges will be strict about the SemVer .br strings that they parse\. .RS 1 .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 release .br type (\fBmajor\fP, \fBpremajor\fP, \fBminor\fP, \fBpreminor\fP, \fBpatch\fP, .br \fBprepatch\fP, or \fBprerelease\fP), or null if it's not valid .RS 1 .IP \(bu 2 \fBpremajor\fP in one call will bump the version up to the next major .br version and down to a prerelease of that major version\. .br \fBpreminor\fP, and \fBprepatch\fP work the same way\. .IP \(bu 2 If called from a non\-prerelease version, the \fBprerelease\fP will work the .br same as \fBprepatch\fP\|\. It increments the patch version, then makes a .br prerelease\. If the input version is already a prerelease it simply .br increments it\. .RE .IP \(bu 2 \fBprerelease(v)\fP: Returns an array of prerelease components, or null .br if 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 ranges .br or comparators intersect\. .IP \(bu 2 \fBparse(v)\fP: Attempt to parse a string as a semantic version, returning either .br a \fBSemVer\fP object or \fBnull\fP\|\. .RE .SS Comparison .RS 1 .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, .br even if they're not the exact same string\. You already know how to .br compare 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 call .br the corresponding function above\. \fB"==="\fP and \fB"!=="\fP do simple .br string comparison, but are included for completeness\. Throws if an .br invalid 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 .br \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 versions .br in descending order when passed to \fBArray\.sort()\fP\|\. .IP \(bu 2 \fBcompareBuild(v1, v2)\fP: The same as \fBcompare\fP but considers \fBbuild\fP when two versions .br are equal\. Sorts in ascending order if passed to \fBArray\.sort()\fP\|\. .br \fBv2\fP is greater\. Sorts in ascending order if passed to \fBArray\.sort()\fP\|\. .IP \(bu 2 \fBdiff(v1, v2)\fP: Returns difference between two versions by the release type .br (\fBmajor\fP, \fBpremajor\fP, \fBminor\fP, \fBpreminor\fP, \fBpatch\fP, \fBprepatch\fP, or \fBprerelease\fP), .br or null if the versions are the same\. .RE .SS Comparators .RS 1 .IP \(bu 2 \fBintersects(comparator)\fP: Return true if the comparators intersect .RE .SS Ranges .RS 1 .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 the .br range\. .IP \(bu 2 \fBmaxSatisfying(versions, range)\fP: Return the highest version in the list .br that satisfies the range, or \fBnull\fP if none of them do\. .IP \(bu 2 \fBminSatisfying(versions, range)\fP: Return the lowest version in the list .br that satisfies the range, or \fBnull\fP if none of them do\. .IP \(bu 2 \fBminVersion(range)\fP: Return the lowest version that can possibly match .br the given range\. .IP \(bu 2 \fBgtr(version, range)\fP: Return \fBtrue\fP if version is greater than all the .br versions possible in the range\. .IP \(bu 2 \fBltr(version, range)\fP: Return \fBtrue\fP if version is less than all the .br versions possible in the range\. .IP \(bu 2 \fBoutside(version, range, hilo)\fP: Return true if the version is outside .br the bounds of the range in either the high or low direction\. The .br \fBhilo\fP argument must be either the string \fB'>'\fP or \fB'<'\fP\|\. (This is .br the function called by \fBgtr\fP and \fBltr\fP\|\.) .IP \(bu 2 \fBintersects(range)\fP: Return true if any of the ranges comparators intersect .IP \(bu 2 \fBsimplifyRange(versions, range)\fP: Return a "simplified" range that .br matches the same items in \fBversions\fP list as the range specified\. Note .br that it does \fInot\fR guarantee that it would match the same versions in all .br cases, only for the set of versions provided\. This is useful when .br generating ranges by joining together multiple versions with \fB||\fP .br programmatically, to provide the user with something a bit more .br ergonomic\. If the provided range is shorter in string\-length than the .br generated range, then that is returned\. .IP \(bu 2 \fBsubset(subRange, superRange)\fP: Return \fBtrue\fP if the \fBsubRange\fP range is .br entirely contained by the \fBsuperRange\fP range\. .RE .P Note that, since ranges may be non\-contiguous, a version might not be .br greater than a range, less than a range, \fIor\fR satisfy a range! For .br example, the range \fB1\.2 <1\.2\.9 || >2\.0\.0\fP would have a hole from \fB1\.2\.9\fP .br until \fB2\.0\.0\fP, so the version \fB1\.2\.10\fP would not be greater than the .br range (because \fB2\.0\.1\fP satisfies, which is higher), nor less than the .br range (since \fB1\.2\.8\fP satisfies, which is lower), and it also does not .br satisfy the range\. .P If you want to know if a version satisfies or does not satisfy a .br range, use the \fBsatisfies(version, range)\fP function\. .SS Coercion .RS 1 .IP \(bu 2 \fBcoerce(version, options)\fP: Coerces a string to semver if possible .RE .P This aims to provide a very forgiving translation of a non\-semver string to .br semver\. It looks for the first digit in a string, and consumes all .br remaining characters which satisfy at least a partial semver (e\.g\., \fB1\fP, .br \fB1\.2\fP, \fB1\.2\.3\fP) up to the max permitted length (256 characters)\. Longer .br versions are simply truncated (\fB4\.6\.3\.9\.2\-alpha2\fP becomes \fB4\.6\.3\fP)\. All .br surrounding text is simply ignored (\fBv3\.4 replaces v3\.3\.1\fP becomes .br \fB3\.4\.0\fP)\. Only text which lacks digits will fail coercion (\fBversion one\fP .br is not valid)\. The maximum length for any semver component considered for .br coercion is 16 characters; longer components will be ignored .br (\fB10000000000000000\.4\.7\.4\fP becomes \fB4\.7\.4\fP)\. The maximum value for any .br semver component is \fBNumber\.MAX_SAFE_INTEGER || (2**53 \- 1)\fP; higher value .br components are invalid (\fB9999999999999999\.4\.7\.4\fP is likely invalid)\. .P If the \fBoptions\.rtl\fP flag is set, then \fBcoerce\fP will return the right\-most .br coercible tuple that does not share an ending index with a longer coercible .br tuple\. For example, \fB1\.2\.3\.4\fP will return \fB2\.3\.4\fP in rtl mode, not .br \fB4\.0\.0\fP\|\. \fB1\.2\.3/4\fP will return \fB4\.0\.0\fP, because the \fB4\fP is not a part of .br any other overlapping SemVer tuple\. .SS Clean .RS 1 .IP \(bu 2 \fBclean(version)\fP: Clean a string to be a valid semver if possible .RE .P This will return a cleaned and trimmed semver version\. If the provided .br version is not valid a null will be returned\. This does not work for .br ranges\. .P ex\. .RS 1 .IP \(bu 2 \fBs\.clean(' = v 2\.1\.5foo')\fP: \fBnull\fP .IP \(bu 2 \fBs\.clean(' = v 2\.1\.5foo', { loose: true })\fP: \fB'2\.1\.5\-foo'\fP .IP \(bu 2 \fBs\.clean(' = v 2\.1\.5\-foo')\fP: \fBnull\fP .IP \(bu 2 \fBs\.clean(' = v 2\.1\.5\-foo', { loose: true })\fP: \fB'2\.1\.5\-foo'\fP .IP \(bu 2 \fBs\.clean('=v2\.1\.5')\fP: \fB'2\.1\.5'\fP .IP \(bu 2 \fBs\.clean(' =v2\.1\.5')\fP: \fB2\.1\.5\fP .IP \(bu 2 \fBs\.clean(' 2\.1\.5 ')\fP: \fB'2\.1\.5'\fP .IP \(bu 2 \fBs\.clean('~1\.0\.0')\fP: \fBnull\fP .RE .SH Constants .P As a convenience, helper constants are exported to provide information about what \fBnode\-semver\fP supports: .SS \fBRELEASE_TYPES\fP .RS 1 .IP \(bu 2 major .IP \(bu 2 premajor .IP \(bu 2 minor .IP \(bu 2 preminor .IP \(bu 2 patch .IP \(bu 2 prepatch .IP \(bu 2 prerelease .RE .RS 2 .nf const semver = require('semver'); if (semver\.RELEASE_TYPES\.includes(arbitraryUserInput)) { console\.log('This is a valid release type!'); } else { console\.warn('This is NOT a valid release type!'); } .fi .RE .SS \fBSEMVER_SPEC_VERSION\fP .P 2\.0\.0 .RS 2 .nf const semver = require('semver'); console\.log('We are currently using the semver specification version:', semver\.SEMVER_SPEC_VERSION); .fi .RE .SH Exported Modules .P You may pull in just the part of this semver utility that you need, if you .br are sensitive to packing and tree\-shaking concerns\. The main .br \fBrequire('semver')\fP export uses getter functions to lazily load the parts .br of the API that are used\. .P The following modules are available: .RS 1 .IP \(bu 2 \fBrequire('semver')\fP .IP \(bu 2 \fBrequire('semver/classes')\fP .IP \(bu 2 \fBrequire('semver/classes/comparator')\fP .IP \(bu 2 \fBrequire('semver/classes/range')\fP .IP \(bu 2 \fBrequire('semver/classes/semver')\fP .IP \(bu 2 \fBrequire('semver/functions/clean')\fP .IP \(bu 2 \fBrequire('semver/functions/cmp')\fP .IP \(bu 2 \fBrequire('semver/functions/coerce')\fP .IP \(bu 2 \fBrequire('semver/functions/compare')\fP .IP \(bu 2 \fBrequire('semver/functions/compare\-build')\fP .IP \(bu 2 \fBrequire('semver/functions/compare\-loose')\fP .IP \(bu 2 \fBrequire('semver/functions/diff')\fP .IP \(bu 2 \fBrequire('semver/functions/eq')\fP .IP \(bu 2 \fBrequire('semver/functions/gt')\fP .IP \(bu 2 \fBrequire('semver/functions/gte')\fP .IP \(bu 2 \fBrequire('semver/functions/inc')\fP .IP \(bu 2 \fBrequire('semver/functions/lt')\fP .IP \(bu 2 \fBrequire('semver/functions/lte')\fP .IP \(bu 2 \fBrequire('semver/functions/major')\fP .IP \(bu 2 \fBrequire('semver/functions/minor')\fP .IP \(bu 2 \fBrequire('semver/functions/neq')\fP .IP \(bu 2 \fBrequire('semver/functions/parse')\fP .IP \(bu 2 \fBrequire('semver/functions/patch')\fP .IP \(bu 2 \fBrequire('semver/functions/prerelease')\fP .IP \(bu 2 \fBrequire('semver/functions/rcompare')\fP .IP \(bu 2 \fBrequire('semver/functions/rsort')\fP .IP \(bu 2 \fBrequire('semver/functions/satisfies')\fP .IP \(bu 2 \fBrequire('semver/functions/sort')\fP .IP \(bu 2 \fBrequire('semver/functions/valid')\fP .IP \(bu 2 \fBrequire('semver/ranges/gtr')\fP .IP \(bu 2 \fBrequire('semver/ranges/intersects')\fP .IP \(bu 2 \fBrequire('semver/ranges/ltr')\fP .IP \(bu 2 \fBrequire('semver/ranges/max\-satisfying')\fP .IP \(bu 2 \fBrequire('semver/ranges/min\-satisfying')\fP .IP \(bu 2 \fBrequire('semver/ranges/min\-version')\fP .IP \(bu 2 \fBrequire('semver/ranges/outside')\fP .IP \(bu 2 \fBrequire('semver/ranges/to\-comparators')\fP .IP \(bu 2 \fBrequire('semver/ranges/valid')\fP .RE