Comparing version 6.2.0 to 6.3.0
# changes log | ||
## 6.2.0 | ||
* Coerce numbers to strings when passed to semver.coerce() | ||
* Add `rtl` option to coerce from right to left | ||
## 6.1.3 | ||
* Handle X-ranges properly in includePrerelease mode | ||
## 6.1.2 | ||
* Do not throw when testing invalid version strings | ||
## 6.1.1 | ||
* Add options support for semver.coerce() | ||
* Handle undefined version passed to Range.test | ||
## 6.1.0 | ||
* Add semver.compareBuild function | ||
* Support `*` in semver.intersects | ||
## 6.0 | ||
@@ -4,0 +27,0 @@ |
{ | ||
"name": "semver", | ||
"version": "6.2.0", | ||
"version": "6.3.0", | ||
"description": "The semantic version parser used by npm.", | ||
@@ -5,0 +5,0 @@ "main": "semver.js", |
245
semver.js
@@ -32,4 +32,9 @@ exports = module.exports = SemVer | ||
var src = exports.src = [] | ||
var t = exports.tokens = {} | ||
var R = 0 | ||
function tok (n) { | ||
t[n] = R++ | ||
} | ||
// The following Regular Expressions can be used for tokenizing, | ||
@@ -41,6 +46,6 @@ // validating, and parsing SemVer version strings. | ||
var NUMERICIDENTIFIER = R++ | ||
src[NUMERICIDENTIFIER] = '0|[1-9]\\d*' | ||
var NUMERICIDENTIFIERLOOSE = R++ | ||
src[NUMERICIDENTIFIERLOOSE] = '[0-9]+' | ||
tok('NUMERICIDENTIFIER') | ||
src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*' | ||
tok('NUMERICIDENTIFIERLOOSE') | ||
src[t.NUMERICIDENTIFIERLOOSE] = '[0-9]+' | ||
@@ -51,4 +56,4 @@ // ## Non-numeric Identifier | ||
var NONNUMERICIDENTIFIER = R++ | ||
src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*' | ||
tok('NONNUMERICIDENTIFIER') | ||
src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*' | ||
@@ -58,11 +63,11 @@ // ## Main Version | ||
var MAINVERSION = R++ | ||
src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + | ||
'(' + src[NUMERICIDENTIFIER] + ')\\.' + | ||
'(' + src[NUMERICIDENTIFIER] + ')' | ||
tok('MAINVERSION') | ||
src[t.MAINVERSION] = '(' + src[t.NUMERICIDENTIFIER] + ')\\.' + | ||
'(' + src[t.NUMERICIDENTIFIER] + ')\\.' + | ||
'(' + src[t.NUMERICIDENTIFIER] + ')' | ||
var MAINVERSIONLOOSE = R++ | ||
src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + | ||
'(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + | ||
'(' + src[NUMERICIDENTIFIERLOOSE] + ')' | ||
tok('MAINVERSIONLOOSE') | ||
src[t.MAINVERSIONLOOSE] = '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' + | ||
'(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' + | ||
'(' + src[t.NUMERICIDENTIFIERLOOSE] + ')' | ||
@@ -72,9 +77,9 @@ // ## Pre-release Version Identifier | ||
var PRERELEASEIDENTIFIER = R++ | ||
src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + | ||
'|' + src[NONNUMERICIDENTIFIER] + ')' | ||
tok('PRERELEASEIDENTIFIER') | ||
src[t.PRERELEASEIDENTIFIER] = '(?:' + src[t.NUMERICIDENTIFIER] + | ||
'|' + src[t.NONNUMERICIDENTIFIER] + ')' | ||
var PRERELEASEIDENTIFIERLOOSE = R++ | ||
src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + | ||
'|' + src[NONNUMERICIDENTIFIER] + ')' | ||
tok('PRERELEASEIDENTIFIERLOOSE') | ||
src[t.PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[t.NUMERICIDENTIFIERLOOSE] + | ||
'|' + src[t.NONNUMERICIDENTIFIER] + ')' | ||
@@ -85,9 +90,9 @@ // ## Pre-release Version | ||
var PRERELEASE = R++ | ||
src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + | ||
'(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))' | ||
tok('PRERELEASE') | ||
src[t.PRERELEASE] = '(?:-(' + src[t.PRERELEASEIDENTIFIER] + | ||
'(?:\\.' + src[t.PRERELEASEIDENTIFIER] + ')*))' | ||
var PRERELEASELOOSE = R++ | ||
src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + | ||
'(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))' | ||
tok('PRERELEASELOOSE') | ||
src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] + | ||
'(?:\\.' + src[t.PRERELEASEIDENTIFIERLOOSE] + ')*))' | ||
@@ -97,4 +102,4 @@ // ## Build Metadata Identifier | ||
var BUILDIDENTIFIER = R++ | ||
src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+' | ||
tok('BUILDIDENTIFIER') | ||
src[t.BUILDIDENTIFIER] = '[0-9A-Za-z-]+' | ||
@@ -105,5 +110,5 @@ // ## Build Metadata | ||
var BUILD = R++ | ||
src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + | ||
'(?:\\.' + src[BUILDIDENTIFIER] + ')*))' | ||
tok('BUILD') | ||
src[t.BUILD] = '(?:\\+(' + src[t.BUILDIDENTIFIER] + | ||
'(?:\\.' + src[t.BUILDIDENTIFIER] + ')*))' | ||
@@ -119,8 +124,9 @@ // ## Full Version String | ||
var FULL = R++ | ||
var FULLPLAIN = 'v?' + src[MAINVERSION] + | ||
src[PRERELEASE] + '?' + | ||
src[BUILD] + '?' | ||
tok('FULL') | ||
tok('FULLPLAIN') | ||
src[t.FULLPLAIN] = 'v?' + src[t.MAINVERSION] + | ||
src[t.PRERELEASE] + '?' + | ||
src[t.BUILD] + '?' | ||
src[FULL] = '^' + FULLPLAIN + '$' | ||
src[t.FULL] = '^' + src[t.FULLPLAIN] + '$' | ||
@@ -130,11 +136,12 @@ // like full, but allows v1.2.3 and =1.2.3, which people do sometimes. | ||
// common in the npm registry. | ||
var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + | ||
src[PRERELEASELOOSE] + '?' + | ||
src[BUILD] + '?' | ||
tok('LOOSEPLAIN') | ||
src[t.LOOSEPLAIN] = '[v=\\s]*' + src[t.MAINVERSIONLOOSE] + | ||
src[t.PRERELEASELOOSE] + '?' + | ||
src[t.BUILD] + '?' | ||
var LOOSE = R++ | ||
src[LOOSE] = '^' + LOOSEPLAIN + '$' | ||
tok('LOOSE') | ||
src[t.LOOSE] = '^' + src[t.LOOSEPLAIN] + '$' | ||
var GTLT = R++ | ||
src[GTLT] = '((?:<|>)?=?)' | ||
tok('GTLT') | ||
src[t.GTLT] = '((?:<|>)?=?)' | ||
@@ -144,32 +151,32 @@ // Something like "2.*" or "1.2.x". | ||
// Only the first item is strictly required. | ||
var XRANGEIDENTIFIERLOOSE = R++ | ||
src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*' | ||
var XRANGEIDENTIFIER = R++ | ||
src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*' | ||
tok('XRANGEIDENTIFIERLOOSE') | ||
src[t.XRANGEIDENTIFIERLOOSE] = src[t.NUMERICIDENTIFIERLOOSE] + '|x|X|\\*' | ||
tok('XRANGEIDENTIFIER') | ||
src[t.XRANGEIDENTIFIER] = src[t.NUMERICIDENTIFIER] + '|x|X|\\*' | ||
var XRANGEPLAIN = R++ | ||
src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + | ||
'(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + | ||
'(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + | ||
'(?:' + src[PRERELEASE] + ')?' + | ||
src[BUILD] + '?' + | ||
tok('XRANGEPLAIN') | ||
src[t.XRANGEPLAIN] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIER] + ')' + | ||
'(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' + | ||
'(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' + | ||
'(?:' + src[t.PRERELEASE] + ')?' + | ||
src[t.BUILD] + '?' + | ||
')?)?' | ||
var XRANGEPLAINLOOSE = R++ | ||
src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + | ||
'(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + | ||
'(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + | ||
'(?:' + src[PRERELEASELOOSE] + ')?' + | ||
src[BUILD] + '?' + | ||
tok('XRANGEPLAINLOOSE') | ||
src[t.XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + | ||
'(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + | ||
'(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' + | ||
'(?:' + src[t.PRERELEASELOOSE] + ')?' + | ||
src[t.BUILD] + '?' + | ||
')?)?' | ||
var XRANGE = R++ | ||
src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$' | ||
var XRANGELOOSE = R++ | ||
src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$' | ||
tok('XRANGE') | ||
src[t.XRANGE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAIN] + '$' | ||
tok('XRANGELOOSE') | ||
src[t.XRANGELOOSE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAINLOOSE] + '$' | ||
// Coercion. | ||
// Extract anything that could conceivably be a part of a valid semver | ||
var COERCE = R++ | ||
src[COERCE] = '(^|[^\\d])' + | ||
tok('COERCE') | ||
src[t.COERCE] = '(^|[^\\d])' + | ||
'(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' + | ||
@@ -179,49 +186,49 @@ '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' + | ||
'(?:$|[^\\d])' | ||
var COERCERTL = R++ | ||
re[COERCERTL] = new RegExp(src[COERCE], 'g') | ||
tok('COERCERTL') | ||
re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g') | ||
// Tilde ranges. | ||
// Meaning is "reasonably at or greater than" | ||
var LONETILDE = R++ | ||
src[LONETILDE] = '(?:~>?)' | ||
tok('LONETILDE') | ||
src[t.LONETILDE] = '(?:~>?)' | ||
var TILDETRIM = R++ | ||
src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+' | ||
re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g') | ||
tok('TILDETRIM') | ||
src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+' | ||
re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g') | ||
var tildeTrimReplace = '$1~' | ||
var TILDE = R++ | ||
src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$' | ||
var TILDELOOSE = R++ | ||
src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$' | ||
tok('TILDE') | ||
src[t.TILDE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAIN] + '$' | ||
tok('TILDELOOSE') | ||
src[t.TILDELOOSE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAINLOOSE] + '$' | ||
// Caret ranges. | ||
// Meaning is "at least and backwards compatible with" | ||
var LONECARET = R++ | ||
src[LONECARET] = '(?:\\^)' | ||
tok('LONECARET') | ||
src[t.LONECARET] = '(?:\\^)' | ||
var CARETTRIM = R++ | ||
src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+' | ||
re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g') | ||
tok('CARETTRIM') | ||
src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+' | ||
re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g') | ||
var caretTrimReplace = '$1^' | ||
var CARET = R++ | ||
src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$' | ||
var CARETLOOSE = R++ | ||
src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$' | ||
tok('CARET') | ||
src[t.CARET] = '^' + src[t.LONECARET] + src[t.XRANGEPLAIN] + '$' | ||
tok('CARETLOOSE') | ||
src[t.CARETLOOSE] = '^' + src[t.LONECARET] + src[t.XRANGEPLAINLOOSE] + '$' | ||
// A simple gt/lt/eq thing, or just "" to indicate "any version" | ||
var COMPARATORLOOSE = R++ | ||
src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$' | ||
var COMPARATOR = R++ | ||
src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$' | ||
tok('COMPARATORLOOSE') | ||
src[t.COMPARATORLOOSE] = '^' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + ')$|^$' | ||
tok('COMPARATOR') | ||
src[t.COMPARATOR] = '^' + src[t.GTLT] + '\\s*(' + src[t.FULLPLAIN] + ')$|^$' | ||
// An expression to strip any whitespace between the gtlt and the thing | ||
// it modifies, so that `> 1.2.3` ==> `>1.2.3` | ||
var COMPARATORTRIM = R++ | ||
src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + | ||
'\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')' | ||
tok('COMPARATORTRIM') | ||
src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] + | ||
'\\s*(' + src[t.LOOSEPLAIN] + '|' + src[t.XRANGEPLAIN] + ')' | ||
// this one has to use the /g flag | ||
re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g') | ||
re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g') | ||
var comparatorTrimReplace = '$1$2$3' | ||
@@ -233,17 +240,17 @@ | ||
// later. | ||
var HYPHENRANGE = R++ | ||
src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + | ||
tok('HYPHENRANGE') | ||
src[t.HYPHENRANGE] = '^\\s*(' + src[t.XRANGEPLAIN] + ')' + | ||
'\\s+-\\s+' + | ||
'(' + src[XRANGEPLAIN] + ')' + | ||
'(' + src[t.XRANGEPLAIN] + ')' + | ||
'\\s*$' | ||
var HYPHENRANGELOOSE = R++ | ||
src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + | ||
tok('HYPHENRANGELOOSE') | ||
src[t.HYPHENRANGELOOSE] = '^\\s*(' + src[t.XRANGEPLAINLOOSE] + ')' + | ||
'\\s+-\\s+' + | ||
'(' + src[XRANGEPLAINLOOSE] + ')' + | ||
'(' + src[t.XRANGEPLAINLOOSE] + ')' + | ||
'\\s*$' | ||
// Star ranges basically just allow anything at all. | ||
var STAR = R++ | ||
src[STAR] = '(<|>)?=?\\s*\\*' | ||
tok('STAR') | ||
src[t.STAR] = '(<|>)?=?\\s*\\*' | ||
@@ -280,3 +287,3 @@ // Compile to actual regexp objects. | ||
var r = options.loose ? re[LOOSE] : re[FULL] | ||
var r = options.loose ? re[t.LOOSE] : re[t.FULL] | ||
if (!r.test(version)) { | ||
@@ -336,3 +343,3 @@ return null | ||
var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL]) | ||
var m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]) | ||
@@ -798,3 +805,3 @@ if (!m) { | ||
Comparator.prototype.parse = function (comp) { | ||
var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR] | ||
var r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR] | ||
var m = comp.match(r) | ||
@@ -954,14 +961,14 @@ | ||
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4` | ||
var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE] | ||
var hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE] | ||
range = range.replace(hr, hyphenReplace) | ||
debug('hyphen replace', range) | ||
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5` | ||
range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace) | ||
debug('comparator trim', range, re[COMPARATORTRIM]) | ||
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace) | ||
debug('comparator trim', range, re[t.COMPARATORTRIM]) | ||
// `~ 1.2.3` => `~1.2.3` | ||
range = range.replace(re[TILDETRIM], tildeTrimReplace) | ||
range = range.replace(re[t.TILDETRIM], tildeTrimReplace) | ||
// `^ 1.2.3` => `^1.2.3` | ||
range = range.replace(re[CARETTRIM], caretTrimReplace) | ||
range = range.replace(re[t.CARETTRIM], caretTrimReplace) | ||
@@ -974,3 +981,3 @@ // normalize spaces | ||
var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR] | ||
var compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR] | ||
var set = range.split(' ').map(function (comp) { | ||
@@ -1075,3 +1082,3 @@ return parseComparator(comp, this.options) | ||
function replaceTilde (comp, options) { | ||
var r = options.loose ? re[TILDELOOSE] : re[TILDE] | ||
var r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE] | ||
return comp.replace(r, function (_, M, m, p, pr) { | ||
@@ -1117,3 +1124,3 @@ debug('tilde', comp, _, M, m, p, pr) | ||
debug('caret', comp, options) | ||
var r = options.loose ? re[CARETLOOSE] : re[CARET] | ||
var r = options.loose ? re[t.CARETLOOSE] : re[t.CARET] | ||
return comp.replace(r, function (_, M, m, p, pr) { | ||
@@ -1177,3 +1184,3 @@ debug('caret', comp, _, M, m, p, pr) | ||
comp = comp.trim() | ||
var r = options.loose ? re[XRANGELOOSE] : re[XRANGE] | ||
var r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE] | ||
return comp.replace(r, function (ret, gtlt, M, m, p, pr) { | ||
@@ -1253,6 +1260,6 @@ debug('xRange', comp, ret, gtlt, M, m, p, pr) | ||
// Looseness is ignored here. star is always as loose as it gets! | ||
return comp.trim().replace(re[STAR], '') | ||
return comp.trim().replace(re[t.STAR], '') | ||
} | ||
// This function is passed to string.replace(re[HYPHENRANGE]) | ||
// This function is passed to string.replace(re[t.HYPHENRANGE]) | ||
// M, m, patch, prerelease, build | ||
@@ -1580,3 +1587,3 @@ // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5 | ||
if (!options.rtl) { | ||
match = version.match(re[COERCE]) | ||
match = version.match(re[t.COERCE]) | ||
} else { | ||
@@ -1592,3 +1599,3 @@ // Find the right-most coercible string that does not share | ||
var next | ||
while ((next = re[COERCERTL].exec(version)) && | ||
while ((next = re[t.COERCERTL].exec(version)) && | ||
(!match || match.index + match[0].length !== version.length) | ||
@@ -1600,6 +1607,6 @@ ) { | ||
} | ||
re[COERCERTL].lastIndex = next.index + next[1].length + next[2].length | ||
re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length | ||
} | ||
// leave it in a clean state | ||
re[COERCERTL].lastIndex = -1 | ||
re[t.COERCERTL].lastIndex = -1 | ||
} | ||
@@ -1606,0 +1613,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
1524
0
67071
7