Socket
Socket
Sign inDemoInstall

semver

Package Overview
Dependencies
Maintainers
2
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

semver - npm Package Compare versions

Comparing version 5.6.0 to 5.7.0

CHANGELOG.md

14

package.json
{
"name": "semver",
"version": "5.6.0",
"version": "5.7.0",
"description": "The semantic version parser used by npm.",
"main": "semver.js",
"scripts": {
"test": "tap test/*.js --cov -J"
"test": "tap",
"preversion": "npm test",
"postversion": "npm publish",
"postpublish": "git push origin --all; git push origin --tags"
},
"devDependencies": {
"tap": "^12.0.1"
"tap": "^13.0.0-rc.18"
},

@@ -21,3 +24,6 @@ "license": "ISC",

"semver.js"
]
],
"tap": {
"check-coverage": true
}
}

@@ -23,2 +23,3 @@ semver(1) -- The semantic versioner for npm

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'

@@ -33,3 +34,3 @@ semver.valid(semver.coerce('42.6.7.9.3-alpha')) // '42.6.7'

A JavaScript implementation of the http://semver.org/ specification
A JavaScript implementation of the https://semver.org/ specification
Copyright Isaac Z. Schlueter

@@ -76,3 +77,3 @@

A "version" is described by the `v2.0.0` specification found at
<http://semver.org/>.
<https://semver.org/>.

@@ -143,2 +144,9 @@ A leading `"="` or `"v"` character is stripped off and ignored.

Note that this behavior can be suppressed (treating all prerelease
versions as if they were normal versions, for the purpose of range
matching) by setting the `includePrerelease` flag on the options
object to any
[functions](https://github.com/npm/node-semver#functions) that do
range matching.
#### Prerelease Identifiers

@@ -332,2 +340,4 @@

or comparators intersect.
* `parse(v)`: Attempt to parse a string as a semantic version, returning either
a `SemVer` object or `null`.

@@ -369,2 +379,4 @@ ### Comparison

that satisfies the range, or `null` if none of them do.
* `minVersion(range)`: Return the lowest version that can possibly match
the given range.
* `gtr(version, range)`: Return `true` if version is greater than all the

@@ -371,0 +383,0 @@ versions possible in the range.

@@ -1,31 +0,33 @@

exports = module.exports = SemVer;
exports = module.exports = SemVer
// The debug function is excluded entirely from the minified version.
/* nomin */ var debug;
/* nomin */ if (typeof process === 'object' &&
/* nomin */ process.env &&
/* nomin */ process.env.NODE_DEBUG &&
/* nomin */ /\bsemver\b/i.test(process.env.NODE_DEBUG))
/* nomin */ debug = function() {
/* nomin */ var args = Array.prototype.slice.call(arguments, 0);
/* nomin */ args.unshift('SEMVER');
/* nomin */ console.log.apply(console, args);
/* nomin */ };
/* nomin */ else
/* nomin */ debug = function() {};
var debug
/* istanbul ignore next */
if (typeof process === 'object' &&
process.env &&
process.env.NODE_DEBUG &&
/\bsemver\b/i.test(process.env.NODE_DEBUG)) {
debug = function () {
var args = Array.prototype.slice.call(arguments, 0)
args.unshift('SEMVER')
console.log.apply(console, args)
}
} else {
debug = function () {}
}
// Note: this is the semver.org version of the spec that it implements
// Not necessarily the package version of this code.
exports.SEMVER_SPEC_VERSION = '2.0.0';
exports.SEMVER_SPEC_VERSION = '2.0.0'
var MAX_LENGTH = 256;
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
var MAX_LENGTH = 256
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
/* istanbul ignore next */ 9007199254740991
// Max safe segment length for coercion.
var MAX_SAFE_COMPONENT_LENGTH = 16;
var MAX_SAFE_COMPONENT_LENGTH = 16
// The actual regexps go on exports.re
var re = exports.re = [];
var src = exports.src = [];
var R = 0;
var re = exports.re = []
var src = exports.src = []
var R = 0

@@ -38,8 +40,7 @@ // The following Regular Expressions can be used for tokenizing,

var NUMERICIDENTIFIER = R++;
src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
var NUMERICIDENTIFIERLOOSE = R++;
src[NUMERICIDENTIFIERLOOSE] = '[0-9]+';
var NUMERICIDENTIFIER = R++
src[NUMERICIDENTIFIER] = '0|[1-9]\\d*'
var NUMERICIDENTIFIERLOOSE = R++
src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'
// ## Non-numeric Identifier

@@ -49,18 +50,17 @@ // Zero or more digits, followed by a letter or hyphen, and then zero or

var NONNUMERICIDENTIFIER = R++;
src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*';
var NONNUMERICIDENTIFIER = R++
src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'
// ## Main Version
// Three dot-separated numeric identifiers.
var MAINVERSION = R++;
var MAINVERSION = R++
src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' +
'(' + src[NUMERICIDENTIFIER] + ')\\.' +
'(' + src[NUMERICIDENTIFIER] + ')';
'(' + src[NUMERICIDENTIFIER] + ')'
var MAINVERSIONLOOSE = R++;
var MAINVERSIONLOOSE = R++
src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
'(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
'(' + src[NUMERICIDENTIFIERLOOSE] + ')';
'(' + src[NUMERICIDENTIFIERLOOSE] + ')'

@@ -70,11 +70,10 @@ // ## Pre-release Version Identifier

var PRERELEASEIDENTIFIER = R++;
var PRERELEASEIDENTIFIER = R++
src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] +
'|' + src[NONNUMERICIDENTIFIER] + ')';
'|' + src[NONNUMERICIDENTIFIER] + ')'
var PRERELEASEIDENTIFIERLOOSE = R++;
var PRERELEASEIDENTIFIERLOOSE = R++
src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] +
'|' + src[NONNUMERICIDENTIFIER] + ')';
'|' + src[NONNUMERICIDENTIFIER] + ')'
// ## Pre-release Version

@@ -84,9 +83,9 @@ // Hyphen, followed by one or more dot-separated pre-release version

var PRERELEASE = R++;
var PRERELEASE = R++
src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] +
'(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
'(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))'
var PRERELEASELOOSE = R++;
var PRERELEASELOOSE = R++
src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] +
'(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))';
'(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'

@@ -96,4 +95,4 @@ // ## Build Metadata Identifier

var BUILDIDENTIFIER = R++;
src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+';
var BUILDIDENTIFIER = R++
src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'

@@ -104,7 +103,6 @@ // ## Build Metadata

var BUILD = R++;
var BUILD = R++
src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
'(?:\\.' + src[BUILDIDENTIFIER] + ')*))';
'(?:\\.' + src[BUILDIDENTIFIER] + ')*))'
// ## Full Version String

@@ -119,8 +117,8 @@ // A main version, followed optionally by a pre-release version and

var FULL = R++;
var FULL = R++
var FULLPLAIN = 'v?' + src[MAINVERSION] +
src[PRERELEASE] + '?' +
src[BUILD] + '?';
src[BUILD] + '?'
src[FULL] = '^' + FULLPLAIN + '$';
src[FULL] = '^' + FULLPLAIN + '$'

@@ -132,9 +130,9 @@ // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.

src[PRERELEASELOOSE] + '?' +
src[BUILD] + '?';
src[BUILD] + '?'
var LOOSE = R++;
src[LOOSE] = '^' + LOOSEPLAIN + '$';
var LOOSE = R++
src[LOOSE] = '^' + LOOSEPLAIN + '$'
var GTLT = R++;
src[GTLT] = '((?:<|>)?=?)';
var GTLT = R++
src[GTLT] = '((?:<|>)?=?)'

@@ -144,8 +142,8 @@ // 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|\\*';
var XRANGEIDENTIFIERLOOSE = R++
src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*'
var XRANGEIDENTIFIER = R++
src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*'
var XRANGEPLAIN = R++;
var XRANGEPLAIN = R++
src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' +

@@ -156,5 +154,5 @@ '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +

src[BUILD] + '?' +
')?)?';
')?)?'
var XRANGEPLAINLOOSE = R++;
var XRANGEPLAINLOOSE = R++
src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' +

@@ -165,12 +163,12 @@ '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +

src[BUILD] + '?' +
')?)?';
')?)?'
var XRANGE = R++;
src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
var XRANGELOOSE = R++;
src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$';
var XRANGE = R++
src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$'
var XRANGELOOSE = R++
src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'
// Coercion.
// Extract anything that could conceivably be a part of a valid semver
var COERCE = R++;
var COERCE = R++
src[COERCE] = '(?:^|[^\\d])' +

@@ -180,52 +178,50 @@ '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' +

'(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
'(?:$|[^\\d])';
'(?:$|[^\\d])'
// Tilde ranges.
// Meaning is "reasonably at or greater than"
var LONETILDE = R++;
src[LONETILDE] = '(?:~>?)';
var LONETILDE = R++
src[LONETILDE] = '(?:~>?)'
var TILDETRIM = R++;
src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
var tildeTrimReplace = '$1~';
var TILDETRIM = R++
src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+'
re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g')
var tildeTrimReplace = '$1~'
var TILDE = R++;
src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
var TILDELOOSE = R++;
src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$';
var TILDE = R++
src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$'
var TILDELOOSE = R++
src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'
// Caret ranges.
// Meaning is "at least and backwards compatible with"
var LONECARET = R++;
src[LONECARET] = '(?:\\^)';
var LONECARET = R++
src[LONECARET] = '(?:\\^)'
var CARETTRIM = R++;
src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
var caretTrimReplace = '$1^';
var CARETTRIM = R++
src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+'
re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g')
var caretTrimReplace = '$1^'
var CARET = R++;
src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
var CARETLOOSE = R++;
src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$';
var CARET = R++
src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$'
var CARETLOOSE = R++
src[CARETLOOSE] = '^' + src[LONECARET] + src[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 + ')$|^$';
var COMPARATORLOOSE = R++
src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$'
var COMPARATOR = R++
src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + 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++;
var COMPARATORTRIM = R++
src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
'\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')';
'\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'
// this one has to use the /g flag
re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
var comparatorTrimReplace = '$1$2$3';
re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g')
var comparatorTrimReplace = '$1$2$3'
// Something like `1.2.3 - 1.2.4`

@@ -235,17 +231,17 @@ // Note that these all use the loose form, because they'll be

// later.
var HYPHENRANGE = R++;
var HYPHENRANGE = R++
src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' +
'\\s+-\\s+' +
'(' + src[XRANGEPLAIN] + ')' +
'\\s*$';
'\\s*$'
var HYPHENRANGELOOSE = R++;
var HYPHENRANGELOOSE = R++
src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' +
'\\s+-\\s+' +
'(' + src[XRANGEPLAINLOOSE] + ')' +
'\\s*$';
'\\s*$'
// Star ranges basically just allow anything at all.
var STAR = R++;
src[STAR] = '(<|>)?=?\\s*\\*';
var STAR = R++
src[STAR] = '(<|>)?=?\\s*\\*'

@@ -255,182 +251,209 @@ // Compile to actual regexp objects.

for (var i = 0; i < R; i++) {
debug(i, src[i]);
if (!re[i])
re[i] = new RegExp(src[i]);
debug(i, src[i])
if (!re[i]) {
re[i] = new RegExp(src[i])
}
}
exports.parse = parse;
function parse(version, options) {
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
exports.parse = parse
function parse (version, options) {
if (!options || typeof options !== 'object') {
options = {
loose: !!options,
includePrerelease: false
}
}
if (version instanceof SemVer)
return version;
if (version instanceof SemVer) {
return version
}
if (typeof version !== 'string')
return null;
if (typeof version !== 'string') {
return null
}
if (version.length > MAX_LENGTH)
return null;
if (version.length > MAX_LENGTH) {
return null
}
var r = options.loose ? re[LOOSE] : re[FULL];
if (!r.test(version))
return null;
var r = options.loose ? re[LOOSE] : re[FULL]
if (!r.test(version)) {
return null
}
try {
return new SemVer(version, options);
return new SemVer(version, options)
} catch (er) {
return null;
return null
}
}
exports.valid = valid;
function valid(version, options) {
var v = parse(version, options);
return v ? v.version : null;
exports.valid = valid
function valid (version, options) {
var v = parse(version, options)
return v ? v.version : null
}
exports.clean = clean;
function clean(version, options) {
var s = parse(version.trim().replace(/^[=v]+/, ''), options);
return s ? s.version : null;
exports.clean = clean
function clean (version, options) {
var s = parse(version.trim().replace(/^[=v]+/, ''), options)
return s ? s.version : null
}
exports.SemVer = SemVer;
exports.SemVer = SemVer
function SemVer(version, options) {
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
function SemVer (version, options) {
if (!options || typeof options !== 'object') {
options = {
loose: !!options,
includePrerelease: false
}
}
if (version instanceof SemVer) {
if (version.loose === options.loose)
return version;
else
version = version.version;
if (version.loose === options.loose) {
return version
} else {
version = version.version
}
} else if (typeof version !== 'string') {
throw new TypeError('Invalid Version: ' + version);
throw new TypeError('Invalid Version: ' + version)
}
if (version.length > MAX_LENGTH)
if (version.length > MAX_LENGTH) {
throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters')
}
if (!(this instanceof SemVer))
return new SemVer(version, options);
if (!(this instanceof SemVer)) {
return new SemVer(version, options)
}
debug('SemVer', version, options);
this.options = options;
this.loose = !!options.loose;
debug('SemVer', version, options)
this.options = options
this.loose = !!options.loose
var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL]);
var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL])
if (!m)
throw new TypeError('Invalid Version: ' + version);
if (!m) {
throw new TypeError('Invalid Version: ' + version)
}
this.raw = version;
this.raw = version
// these are actually numbers
this.major = +m[1];
this.minor = +m[2];
this.patch = +m[3];
this.major = +m[1]
this.minor = +m[2]
this.patch = +m[3]
if (this.major > MAX_SAFE_INTEGER || this.major < 0)
if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
throw new TypeError('Invalid major version')
}
if (this.minor > MAX_SAFE_INTEGER || this.minor < 0)
if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
throw new TypeError('Invalid minor version')
}
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0)
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
throw new TypeError('Invalid patch version')
}
// numberify any prerelease numeric ids
if (!m[4])
this.prerelease = [];
else
this.prerelease = m[4].split('.').map(function(id) {
if (!m[4]) {
this.prerelease = []
} else {
this.prerelease = m[4].split('.').map(function (id) {
if (/^[0-9]+$/.test(id)) {
var num = +id;
if (num >= 0 && num < MAX_SAFE_INTEGER)
return num;
var num = +id
if (num >= 0 && num < MAX_SAFE_INTEGER) {
return num
}
}
return id;
});
return id
})
}
this.build = m[5] ? m[5].split('.') : [];
this.format();
this.build = m[5] ? m[5].split('.') : []
this.format()
}
SemVer.prototype.format = function() {
this.version = this.major + '.' + this.minor + '.' + this.patch;
if (this.prerelease.length)
this.version += '-' + this.prerelease.join('.');
return this.version;
};
SemVer.prototype.format = function () {
this.version = this.major + '.' + this.minor + '.' + this.patch
if (this.prerelease.length) {
this.version += '-' + this.prerelease.join('.')
}
return this.version
}
SemVer.prototype.toString = function() {
return this.version;
};
SemVer.prototype.toString = function () {
return this.version
}
SemVer.prototype.compare = function(other) {
debug('SemVer.compare', this.version, this.options, other);
if (!(other instanceof SemVer))
other = new SemVer(other, this.options);
SemVer.prototype.compare = function (other) {
debug('SemVer.compare', this.version, this.options, other)
if (!(other instanceof SemVer)) {
other = new SemVer(other, this.options)
}
return this.compareMain(other) || this.comparePre(other);
};
return this.compareMain(other) || this.comparePre(other)
}
SemVer.prototype.compareMain = function(other) {
if (!(other instanceof SemVer))
other = new SemVer(other, this.options);
SemVer.prototype.compareMain = function (other) {
if (!(other instanceof SemVer)) {
other = new SemVer(other, this.options)
}
return compareIdentifiers(this.major, other.major) ||
compareIdentifiers(this.minor, other.minor) ||
compareIdentifiers(this.patch, other.patch);
};
compareIdentifiers(this.patch, other.patch)
}
SemVer.prototype.comparePre = function(other) {
if (!(other instanceof SemVer))
other = new SemVer(other, this.options);
SemVer.prototype.comparePre = function (other) {
if (!(other instanceof SemVer)) {
other = new SemVer(other, this.options)
}
// NOT having a prerelease is > having one
if (this.prerelease.length && !other.prerelease.length)
return -1;
else if (!this.prerelease.length && other.prerelease.length)
return 1;
else if (!this.prerelease.length && !other.prerelease.length)
return 0;
if (this.prerelease.length && !other.prerelease.length) {
return -1
} else if (!this.prerelease.length && other.prerelease.length) {
return 1
} else if (!this.prerelease.length && !other.prerelease.length) {
return 0
}
var i = 0;
var i = 0
do {
var a = this.prerelease[i];
var b = other.prerelease[i];
debug('prerelease compare', i, a, b);
if (a === undefined && b === undefined)
return 0;
else if (b === undefined)
return 1;
else if (a === undefined)
return -1;
else if (a === b)
continue;
else
return compareIdentifiers(a, b);
} while (++i);
};
var a = this.prerelease[i]
var b = other.prerelease[i]
debug('prerelease compare', i, a, b)
if (a === undefined && b === undefined) {
return 0
} else if (b === undefined) {
return 1
} else if (a === undefined) {
return -1
} else if (a === b) {
continue
} else {
return compareIdentifiers(a, b)
}
} while (++i)
}
// preminor will bump the version up to the next minor release, and immediately
// down to pre-release. premajor and prepatch work the same way.
SemVer.prototype.inc = function(release, identifier) {
SemVer.prototype.inc = function (release, identifier) {
switch (release) {
case 'premajor':
this.prerelease.length = 0;
this.patch = 0;
this.minor = 0;
this.major++;
this.inc('pre', identifier);
break;
this.prerelease.length = 0
this.patch = 0
this.minor = 0
this.major++
this.inc('pre', identifier)
break
case 'preminor':
this.prerelease.length = 0;
this.patch = 0;
this.minor++;
this.inc('pre', identifier);
break;
this.prerelease.length = 0
this.patch = 0
this.minor++
this.inc('pre', identifier)
break
case 'prepatch':

@@ -440,13 +463,14 @@ // If this is already a prerelease, it will bump to the next version

// relevant at this point.
this.prerelease.length = 0;
this.inc('patch', identifier);
this.inc('pre', identifier);
break;
this.prerelease.length = 0
this.inc('patch', identifier)
this.inc('pre', identifier)
break
// If the input is a non-prerelease version, this acts the same as
// prepatch.
case 'prerelease':
if (this.prerelease.length === 0)
this.inc('patch', identifier);
this.inc('pre', identifier);
break;
if (this.prerelease.length === 0) {
this.inc('patch', identifier)
}
this.inc('pre', identifier)
break

@@ -458,8 +482,11 @@ case 'major':

// 1.1.0 bumps to 2.0.0
if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0)
this.major++;
this.minor = 0;
this.patch = 0;
this.prerelease = [];
break;
if (this.minor !== 0 ||
this.patch !== 0 ||
this.prerelease.length === 0) {
this.major++
}
this.minor = 0
this.patch = 0
this.prerelease = []
break
case 'minor':

@@ -470,7 +497,8 @@ // If this is a pre-minor version, bump up to the same minor version.

// 1.2.1 bumps to 1.3.0
if (this.patch !== 0 || this.prerelease.length === 0)
this.minor++;
this.patch = 0;
this.prerelease = [];
break;
if (this.patch !== 0 || this.prerelease.length === 0) {
this.minor++
}
this.patch = 0
this.prerelease = []
break
case 'patch':

@@ -481,21 +509,24 @@ // If this is not a pre-release version, it will increment the patch.

// 1.2.0 patches to 1.2.1
if (this.prerelease.length === 0)
this.patch++;
this.prerelease = [];
break;
if (this.prerelease.length === 0) {
this.patch++
}
this.prerelease = []
break
// This probably shouldn't be used publicly.
// 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
case 'pre':
if (this.prerelease.length === 0)
this.prerelease = [0];
else {
var i = this.prerelease.length;
if (this.prerelease.length === 0) {
this.prerelease = [0]
} else {
var i = this.prerelease.length
while (--i >= 0) {
if (typeof this.prerelease[i] === 'number') {
this.prerelease[i]++;
i = -2;
this.prerelease[i]++
i = -2
}
}
if (i === -1) // didn't increment anything
this.prerelease.push(0);
if (i === -1) {
// didn't increment anything
this.prerelease.push(0)
}
}

@@ -506,47 +537,44 @@ if (identifier) {

if (this.prerelease[0] === identifier) {
if (isNaN(this.prerelease[1]))
this.prerelease = [identifier, 0];
} else
this.prerelease = [identifier, 0];
if (isNaN(this.prerelease[1])) {
this.prerelease = [identifier, 0]
}
} else {
this.prerelease = [identifier, 0]
}
}
break;
break
default:
throw new Error('invalid increment argument: ' + release);
throw new Error('invalid increment argument: ' + release)
}
this.format();
this.raw = this.version;
return this;
};
this.format()
this.raw = this.version
return this
}
exports.inc = inc;
function inc(version, release, loose, identifier) {
if (typeof(loose) === 'string') {
identifier = loose;
loose = undefined;
exports.inc = inc
function inc (version, release, loose, identifier) {
if (typeof (loose) === 'string') {
identifier = loose
loose = undefined
}
try {
return new SemVer(version, loose).inc(release, identifier).version;
return new SemVer(version, loose).inc(release, identifier).version
} catch (er) {
return null;
return null
}
}
exports.diff = diff;
function diff(version1, version2) {
exports.diff = diff
function diff (version1, version2) {
if (eq(version1, version2)) {
return null;
return null
} else {
var v1 = parse(version1);
var v2 = parse(version2);
var v1 = parse(version1)
var v2 = parse(version2)
var prefix = ''
if (v1.prerelease.length || v2.prerelease.length) {
for (var key in v1) {
if (key === 'major' || key === 'minor' || key === 'patch') {
if (v1[key] !== v2[key]) {
return 'pre'+key;
}
}
}
return 'prerelease';
prefix = 'pre'
var defaultResult = 'prerelease'
}

@@ -556,211 +584,245 @@ for (var key in v1) {

if (v1[key] !== v2[key]) {
return key;
return prefix + key
}
}
}
return defaultResult // may be undefined
}
}
exports.compareIdentifiers = compareIdentifiers;
exports.compareIdentifiers = compareIdentifiers
var numeric = /^[0-9]+$/;
function compareIdentifiers(a, b) {
var anum = numeric.test(a);
var bnum = numeric.test(b);
var numeric = /^[0-9]+$/
function compareIdentifiers (a, b) {
var anum = numeric.test(a)
var bnum = numeric.test(b)
if (anum && bnum) {
a = +a;
b = +b;
a = +a
b = +b
}
return (anum && !bnum) ? -1 :
(bnum && !anum) ? 1 :
a < b ? -1 :
a > b ? 1 :
0;
return a === b ? 0
: (anum && !bnum) ? -1
: (bnum && !anum) ? 1
: a < b ? -1
: 1
}
exports.rcompareIdentifiers = rcompareIdentifiers;
function rcompareIdentifiers(a, b) {
return compareIdentifiers(b, a);
exports.rcompareIdentifiers = rcompareIdentifiers
function rcompareIdentifiers (a, b) {
return compareIdentifiers(b, a)
}
exports.major = major;
function major(a, loose) {
return new SemVer(a, loose).major;
exports.major = major
function major (a, loose) {
return new SemVer(a, loose).major
}
exports.minor = minor;
function minor(a, loose) {
return new SemVer(a, loose).minor;
exports.minor = minor
function minor (a, loose) {
return new SemVer(a, loose).minor
}
exports.patch = patch;
function patch(a, loose) {
return new SemVer(a, loose).patch;
exports.patch = patch
function patch (a, loose) {
return new SemVer(a, loose).patch
}
exports.compare = compare;
function compare(a, b, loose) {
return new SemVer(a, loose).compare(new SemVer(b, loose));
exports.compare = compare
function compare (a, b, loose) {
return new SemVer(a, loose).compare(new SemVer(b, loose))
}
exports.compareLoose = compareLoose;
function compareLoose(a, b) {
return compare(a, b, true);
exports.compareLoose = compareLoose
function compareLoose (a, b) {
return compare(a, b, true)
}
exports.rcompare = rcompare;
function rcompare(a, b, loose) {
return compare(b, a, loose);
exports.rcompare = rcompare
function rcompare (a, b, loose) {
return compare(b, a, loose)
}
exports.sort = sort;
function sort(list, loose) {
return list.sort(function(a, b) {
return exports.compare(a, b, loose);
});
exports.sort = sort
function sort (list, loose) {
return list.sort(function (a, b) {
return exports.compare(a, b, loose)
})
}
exports.rsort = rsort;
function rsort(list, loose) {
return list.sort(function(a, b) {
return exports.rcompare(a, b, loose);
});
exports.rsort = rsort
function rsort (list, loose) {
return list.sort(function (a, b) {
return exports.rcompare(a, b, loose)
})
}
exports.gt = gt;
function gt(a, b, loose) {
return compare(a, b, loose) > 0;
exports.gt = gt
function gt (a, b, loose) {
return compare(a, b, loose) > 0
}
exports.lt = lt;
function lt(a, b, loose) {
return compare(a, b, loose) < 0;
exports.lt = lt
function lt (a, b, loose) {
return compare(a, b, loose) < 0
}
exports.eq = eq;
function eq(a, b, loose) {
return compare(a, b, loose) === 0;
exports.eq = eq
function eq (a, b, loose) {
return compare(a, b, loose) === 0
}
exports.neq = neq;
function neq(a, b, loose) {
return compare(a, b, loose) !== 0;
exports.neq = neq
function neq (a, b, loose) {
return compare(a, b, loose) !== 0
}
exports.gte = gte;
function gte(a, b, loose) {
return compare(a, b, loose) >= 0;
exports.gte = gte
function gte (a, b, loose) {
return compare(a, b, loose) >= 0
}
exports.lte = lte;
function lte(a, b, loose) {
return compare(a, b, loose) <= 0;
exports.lte = lte
function lte (a, b, loose) {
return compare(a, b, loose) <= 0
}
exports.cmp = cmp;
function cmp(a, op, b, loose) {
var ret;
exports.cmp = cmp
function cmp (a, op, b, loose) {
switch (op) {
case '===':
if (typeof a === 'object') a = a.version;
if (typeof b === 'object') b = b.version;
ret = a === b;
break;
if (typeof a === 'object')
a = a.version
if (typeof b === 'object')
b = b.version
return a === b
case '!==':
if (typeof a === 'object') a = a.version;
if (typeof b === 'object') b = b.version;
ret = a !== b;
break;
case '': case '=': case '==': ret = eq(a, b, loose); break;
case '!=': ret = neq(a, b, loose); break;
case '>': ret = gt(a, b, loose); break;
case '>=': ret = gte(a, b, loose); break;
case '<': ret = lt(a, b, loose); break;
case '<=': ret = lte(a, b, loose); break;
default: throw new TypeError('Invalid operator: ' + op);
if (typeof a === 'object')
a = a.version
if (typeof b === 'object')
b = b.version
return a !== b
case '':
case '=':
case '==':
return eq(a, b, loose)
case '!=':
return neq(a, b, loose)
case '>':
return gt(a, b, loose)
case '>=':
return gte(a, b, loose)
case '<':
return lt(a, b, loose)
case '<=':
return lte(a, b, loose)
default:
throw new TypeError('Invalid operator: ' + op)
}
return ret;
}
exports.Comparator = Comparator;
function Comparator(comp, options) {
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
exports.Comparator = Comparator
function Comparator (comp, options) {
if (!options || typeof options !== 'object') {
options = {
loose: !!options,
includePrerelease: false
}
}
if (comp instanceof Comparator) {
if (comp.loose === !!options.loose)
return comp;
else
comp = comp.value;
if (comp.loose === !!options.loose) {
return comp
} else {
comp = comp.value
}
}
if (!(this instanceof Comparator))
return new Comparator(comp, options);
if (!(this instanceof Comparator)) {
return new Comparator(comp, options)
}
debug('comparator', comp, options);
this.options = options;
this.loose = !!options.loose;
this.parse(comp);
debug('comparator', comp, options)
this.options = options
this.loose = !!options.loose
this.parse(comp)
if (this.semver === ANY)
this.value = '';
else
this.value = this.operator + this.semver.version;
if (this.semver === ANY) {
this.value = ''
} else {
this.value = this.operator + this.semver.version
}
debug('comp', this);
debug('comp', this)
}
var ANY = {};
Comparator.prototype.parse = function(comp) {
var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
var m = comp.match(r);
var ANY = {}
Comparator.prototype.parse = function (comp) {
var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR]
var m = comp.match(r)
if (!m)
throw new TypeError('Invalid comparator: ' + comp);
if (!m) {
throw new TypeError('Invalid comparator: ' + comp)
}
this.operator = m[1];
if (this.operator === '=')
this.operator = '';
this.operator = m[1]
if (this.operator === '=') {
this.operator = ''
}
// if it literally is just '>' or '' then allow anything.
if (!m[2])
this.semver = ANY;
else
this.semver = new SemVer(m[2], this.options.loose);
};
if (!m[2]) {
this.semver = ANY
} else {
this.semver = new SemVer(m[2], this.options.loose)
}
}
Comparator.prototype.toString = function() {
return this.value;
};
Comparator.prototype.toString = function () {
return this.value
}
Comparator.prototype.test = function(version) {
debug('Comparator.test', version, this.options.loose);
Comparator.prototype.test = function (version) {
debug('Comparator.test', version, this.options.loose)
if (this.semver === ANY)
return true;
if (this.semver === ANY) {
return true
}
if (typeof version === 'string')
version = new SemVer(version, this.options);
if (typeof version === 'string') {
version = new SemVer(version, this.options)
}
return cmp(version, this.operator, this.semver, this.options);
};
return cmp(version, this.operator, this.semver, this.options)
}
Comparator.prototype.intersects = function(comp, options) {
Comparator.prototype.intersects = function (comp, options) {
if (!(comp instanceof Comparator)) {
throw new TypeError('a Comparator is required');
throw new TypeError('a Comparator is required')
}
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
if (!options || typeof options !== 'object') {
options = {
loose: !!options,
includePrerelease: false
}
}
var rangeTmp;
var rangeTmp
if (this.operator === '') {
rangeTmp = new Range(comp.value, options);
return satisfies(this.value, rangeTmp, options);
rangeTmp = new Range(comp.value, options)
return satisfies(this.value, rangeTmp, options)
} else if (comp.operator === '') {
rangeTmp = new Range(this.value, options);
return satisfies(comp.semver, rangeTmp, options);
rangeTmp = new Range(this.value, options)
return satisfies(comp.semver, rangeTmp, options)
}

@@ -770,36 +832,39 @@

(this.operator === '>=' || this.operator === '>') &&
(comp.operator === '>=' || comp.operator === '>');
(comp.operator === '>=' || comp.operator === '>')
var sameDirectionDecreasing =
(this.operator === '<=' || this.operator === '<') &&
(comp.operator === '<=' || comp.operator === '<');
var sameSemVer = this.semver.version === comp.semver.version;
(comp.operator === '<=' || comp.operator === '<')
var sameSemVer = this.semver.version === comp.semver.version
var differentDirectionsInclusive =
(this.operator === '>=' || this.operator === '<=') &&
(comp.operator === '>=' || comp.operator === '<=');
(comp.operator === '>=' || comp.operator === '<=')
var oppositeDirectionsLessThan =
cmp(this.semver, '<', comp.semver, options) &&
((this.operator === '>=' || this.operator === '>') &&
(comp.operator === '<=' || comp.operator === '<'));
(comp.operator === '<=' || comp.operator === '<'))
var oppositeDirectionsGreaterThan =
cmp(this.semver, '>', comp.semver, options) &&
((this.operator === '<=' || this.operator === '<') &&
(comp.operator === '>=' || comp.operator === '>'));
(comp.operator === '>=' || comp.operator === '>'))
return sameDirectionIncreasing || sameDirectionDecreasing ||
(sameSemVer && differentDirectionsInclusive) ||
oppositeDirectionsLessThan || oppositeDirectionsGreaterThan;
};
oppositeDirectionsLessThan || oppositeDirectionsGreaterThan
}
exports.Range = Range
function Range (range, options) {
if (!options || typeof options !== 'object') {
options = {
loose: !!options,
includePrerelease: false
}
}
exports.Range = Range;
function Range(range, options) {
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
if (range instanceof Range) {
if (range.loose === !!options.loose &&
range.includePrerelease === !!options.includePrerelease) {
return range;
return range
} else {
return new Range(range.raw, options);
return new Range(range.raw, options)
}

@@ -809,58 +874,59 @@ }

if (range instanceof Comparator) {
return new Range(range.value, options);
return new Range(range.value, options)
}
if (!(this instanceof Range))
return new Range(range, options);
if (!(this instanceof Range)) {
return new Range(range, options)
}
this.options = options;
this.loose = !!options.loose;
this.options = options
this.loose = !!options.loose
this.includePrerelease = !!options.includePrerelease
// First, split based on boolean or ||
this.raw = range;
this.set = range.split(/\s*\|\|\s*/).map(function(range) {
return this.parseRange(range.trim());
}, this).filter(function(c) {
this.raw = range
this.set = range.split(/\s*\|\|\s*/).map(function (range) {
return this.parseRange(range.trim())
}, this).filter(function (c) {
// throw out any that are not relevant for whatever reason
return c.length;
});
return c.length
})
if (!this.set.length) {
throw new TypeError('Invalid SemVer Range: ' + range);
throw new TypeError('Invalid SemVer Range: ' + range)
}
this.format();
this.format()
}
Range.prototype.format = function() {
this.range = this.set.map(function(comps) {
return comps.join(' ').trim();
}).join('||').trim();
return this.range;
};
Range.prototype.format = function () {
this.range = this.set.map(function (comps) {
return comps.join(' ').trim()
}).join('||').trim()
return this.range
}
Range.prototype.toString = function() {
return this.range;
};
Range.prototype.toString = function () {
return this.range
}
Range.prototype.parseRange = function(range) {
var loose = this.options.loose;
range = range.trim();
Range.prototype.parseRange = function (range) {
var loose = this.options.loose
range = range.trim()
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
range = range.replace(hr, hyphenReplace);
debug('hyphen replace', range);
var hr = loose ? re[HYPHENRANGELOOSE] : re[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[COMPARATORTRIM], comparatorTrimReplace)
debug('comparator trim', range, re[COMPARATORTRIM])
// `~ 1.2.3` => `~1.2.3`
range = range.replace(re[TILDETRIM], tildeTrimReplace);
range = range.replace(re[TILDETRIM], tildeTrimReplace)
// `^ 1.2.3` => `^1.2.3`
range = range.replace(re[CARETTRIM], caretTrimReplace);
range = range.replace(re[CARETTRIM], caretTrimReplace)
// normalize spaces
range = range.split(/\s+/).join(' ');
range = range.split(/\s+/).join(' ')

@@ -870,43 +936,43 @@ // At this point, the range is completely trimmed and

var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
var set = range.split(' ').map(function(comp) {
return parseComparator(comp, this.options);
}, this).join(' ').split(/\s+/);
var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR]
var set = range.split(' ').map(function (comp) {
return parseComparator(comp, this.options)
}, this).join(' ').split(/\s+/)
if (this.options.loose) {
// in loose mode, throw out any that are not valid comparators
set = set.filter(function(comp) {
return !!comp.match(compRe);
});
set = set.filter(function (comp) {
return !!comp.match(compRe)
})
}
set = set.map(function(comp) {
return new Comparator(comp, this.options);
}, this);
set = set.map(function (comp) {
return new Comparator(comp, this.options)
}, this)
return set;
};
return set
}
Range.prototype.intersects = function(range, options) {
Range.prototype.intersects = function (range, options) {
if (!(range instanceof Range)) {
throw new TypeError('a Range is required');
throw new TypeError('a Range is required')
}
return this.set.some(function(thisComparators) {
return thisComparators.every(function(thisComparator) {
return range.set.some(function(rangeComparators) {
return rangeComparators.every(function(rangeComparator) {
return thisComparator.intersects(rangeComparator, options);
});
});
});
});
};
return this.set.some(function (thisComparators) {
return thisComparators.every(function (thisComparator) {
return range.set.some(function (rangeComparators) {
return rangeComparators.every(function (rangeComparator) {
return thisComparator.intersects(rangeComparator, options)
})
})
})
})
}
// Mostly just for testing and legacy API reasons
exports.toComparators = toComparators;
function toComparators(range, options) {
return new Range(range, options).set.map(function(comp) {
return comp.map(function(c) {
return c.value;
}).join(' ').trim().split(' ');
});
exports.toComparators = toComparators
function toComparators (range, options) {
return new Range(range, options).set.map(function (comp) {
return comp.map(function (c) {
return c.value
}).join(' ').trim().split(' ')
})
}

@@ -917,17 +983,17 @@

// turn into a set of JUST comparators.
function parseComparator(comp, options) {
debug('comp', comp, options);
comp = replaceCarets(comp, options);
debug('caret', comp);
comp = replaceTildes(comp, options);
debug('tildes', comp);
comp = replaceXRanges(comp, options);
debug('xrange', comp);
comp = replaceStars(comp, options);
debug('stars', comp);
return comp;
function parseComparator (comp, options) {
debug('comp', comp, options)
comp = replaceCarets(comp, options)
debug('caret', comp)
comp = replaceTildes(comp, options)
debug('tildes', comp)
comp = replaceXRanges(comp, options)
debug('xrange', comp)
comp = replaceStars(comp, options)
debug('stars', comp)
return comp
}
function isX(id) {
return !id || id.toLowerCase() === 'x' || id === '*';
function isX (id) {
return !id || id.toLowerCase() === 'x' || id === '*'
}

@@ -941,37 +1007,34 @@

// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
function replaceTildes(comp, options) {
return comp.trim().split(/\s+/).map(function(comp) {
return replaceTilde(comp, options);
}).join(' ');
function replaceTildes (comp, options) {
return comp.trim().split(/\s+/).map(function (comp) {
return replaceTilde(comp, options)
}).join(' ')
}
function replaceTilde(comp, options) {
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
var r = options.loose ? re[TILDELOOSE] : re[TILDE];
return comp.replace(r, function(_, M, m, p, pr) {
debug('tilde', comp, _, M, m, p, pr);
var ret;
function replaceTilde (comp, options) {
var r = options.loose ? re[TILDELOOSE] : re[TILDE]
return comp.replace(r, function (_, M, m, p, pr) {
debug('tilde', comp, _, M, m, p, pr)
var ret
if (isX(M))
ret = '';
else if (isX(m))
ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
else if (isX(p))
if (isX(M)) {
ret = ''
} else if (isX(m)) {
ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
} else if (isX(p)) {
// ~1.2 == >=1.2.0 <1.3.0
ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
else if (pr) {
debug('replaceTilde pr', pr);
if (pr.charAt(0) !== '-')
pr = '-' + pr;
ret = '>=' + M + '.' + m + '.' + p + pr +
' <' + M + '.' + (+m + 1) + '.0';
} else
ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
} else if (pr) {
debug('replaceTilde pr', pr)
ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
' <' + M + '.' + (+m + 1) + '.0'
} else {
// ~1.2.3 == >=1.2.3 <1.3.0
ret = '>=' + M + '.' + m + '.' + p +
' <' + M + '.' + (+m + 1) + '.0';
' <' + M + '.' + (+m + 1) + '.0'
}
debug('tilde return', ret);
return ret;
});
debug('tilde return', ret)
return ret
})
}

@@ -985,80 +1048,80 @@

// ^1.2.0 --> >=1.2.0 <2.0.0
function replaceCarets(comp, options) {
return comp.trim().split(/\s+/).map(function(comp) {
return replaceCaret(comp, options);
}).join(' ');
function replaceCarets (comp, options) {
return comp.trim().split(/\s+/).map(function (comp) {
return replaceCaret(comp, options)
}).join(' ')
}
function replaceCaret(comp, options) {
debug('caret', comp, options);
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
var r = options.loose ? re[CARETLOOSE] : re[CARET];
return comp.replace(r, function(_, M, m, p, pr) {
debug('caret', comp, _, M, m, p, pr);
var ret;
function replaceCaret (comp, options) {
debug('caret', comp, options)
var r = options.loose ? re[CARETLOOSE] : re[CARET]
return comp.replace(r, function (_, M, m, p, pr) {
debug('caret', comp, _, M, m, p, pr)
var ret
if (isX(M))
ret = '';
else if (isX(m))
ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
else if (isX(p)) {
if (M === '0')
ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
else
ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0';
if (isX(M)) {
ret = ''
} else if (isX(m)) {
ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
} else if (isX(p)) {
if (M === '0') {
ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
} else {
ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0'
}
} else if (pr) {
debug('replaceCaret pr', pr);
if (pr.charAt(0) !== '-')
pr = '-' + pr;
debug('replaceCaret pr', pr)
if (M === '0') {
if (m === '0')
ret = '>=' + M + '.' + m + '.' + p + pr +
' <' + M + '.' + m + '.' + (+p + 1);
else
ret = '>=' + M + '.' + m + '.' + p + pr +
' <' + M + '.' + (+m + 1) + '.0';
} else
ret = '>=' + M + '.' + m + '.' + p + pr +
' <' + (+M + 1) + '.0.0';
if (m === '0') {
ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
' <' + M + '.' + m + '.' + (+p + 1)
} else {
ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
' <' + M + '.' + (+m + 1) + '.0'
}
} else {
ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
' <' + (+M + 1) + '.0.0'
}
} else {
debug('no pr');
debug('no pr')
if (M === '0') {
if (m === '0')
if (m === '0') {
ret = '>=' + M + '.' + m + '.' + p +
' <' + M + '.' + m + '.' + (+p + 1);
else
' <' + M + '.' + m + '.' + (+p + 1)
} else {
ret = '>=' + M + '.' + m + '.' + p +
' <' + M + '.' + (+m + 1) + '.0';
} else
' <' + M + '.' + (+m + 1) + '.0'
}
} else {
ret = '>=' + M + '.' + m + '.' + p +
' <' + (+M + 1) + '.0.0';
' <' + (+M + 1) + '.0.0'
}
}
debug('caret return', ret);
return ret;
});
debug('caret return', ret)
return ret
})
}
function replaceXRanges(comp, options) {
debug('replaceXRanges', comp, options);
return comp.split(/\s+/).map(function(comp) {
return replaceXRange(comp, options);
}).join(' ');
function replaceXRanges (comp, options) {
debug('replaceXRanges', comp, options)
return comp.split(/\s+/).map(function (comp) {
return replaceXRange(comp, options)
}).join(' ')
}
function replaceXRange(comp, options) {
comp = comp.trim();
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
var r = options.loose ? re[XRANGELOOSE] : re[XRANGE];
return comp.replace(r, function(ret, gtlt, M, m, p, pr) {
debug('xRange', comp, ret, gtlt, M, m, p, pr);
var xM = isX(M);
var xm = xM || isX(m);
var xp = xm || isX(p);
var anyX = xp;
function replaceXRange (comp, options) {
comp = comp.trim()
var r = options.loose ? re[XRANGELOOSE] : re[XRANGE]
return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
debug('xRange', comp, ret, gtlt, M, m, p, pr)
var xM = isX(M)
var xm = xM || isX(m)
var xp = xm || isX(p)
var anyX = xp
if (gtlt === '=' && anyX)
gtlt = '';
if (gtlt === '=' && anyX) {
gtlt = ''
}

@@ -1068,13 +1131,14 @@ if (xM) {

// nothing is allowed
ret = '<0.0.0';
ret = '<0.0.0'
} else {
// nothing is forbidden
ret = '*';
ret = '*'
}
} else if (gtlt && anyX) {
// we know patch is an x, because we have any x at all.
// replace X with 0
if (xm)
m = 0;
if (xp)
p = 0;
if (xm) {
m = 0
}
p = 0

@@ -1085,10 +1149,10 @@ if (gtlt === '>') {

// >1.2.3 => >= 1.2.4
gtlt = '>=';
gtlt = '>='
if (xm) {
M = +M + 1;
m = 0;
p = 0;
} else if (xp) {
m = +m + 1;
p = 0;
M = +M + 1
m = 0
p = 0
} else {
m = +m + 1
p = 0
}

@@ -1098,20 +1162,21 @@ } else if (gtlt === '<=') {

// pass. Similarly, <=7.x is actually <8.0.0, etc.
gtlt = '<';
if (xm)
M = +M + 1;
else
m = +m + 1;
gtlt = '<'
if (xm) {
M = +M + 1
} else {
m = +m + 1
}
}
ret = gtlt + M + '.' + m + '.' + p;
ret = gtlt + M + '.' + m + '.' + p
} else if (xm) {
ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0';
ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
} else if (xp) {
ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0';
ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
}
debug('xRange return', ret);
debug('xRange return', ret)
return ret;
});
return ret
})
}

@@ -1121,6 +1186,6 @@

// and '' means "any version", just remove the *s entirely.
function replaceStars(comp, options) {
debug('replaceStars', comp, options);
function replaceStars (comp, options) {
debug('replaceStars', comp, options)
// Looseness is ignored here. star is always as loose as it gets!
return comp.trim().replace(re[STAR], '');
return comp.trim().replace(re[STAR], '')
}

@@ -1133,54 +1198,55 @@

// 1.2 - 3.4 => >=1.2.0 <3.5.0
function hyphenReplace($0,
from, fM, fm, fp, fpr, fb,
to, tM, tm, tp, tpr, tb) {
function hyphenReplace ($0,
from, fM, fm, fp, fpr, fb,
to, tM, tm, tp, tpr, tb) {
if (isX(fM)) {
from = ''
} else if (isX(fm)) {
from = '>=' + fM + '.0.0'
} else if (isX(fp)) {
from = '>=' + fM + '.' + fm + '.0'
} else {
from = '>=' + from
}
if (isX(fM))
from = '';
else if (isX(fm))
from = '>=' + fM + '.0.0';
else if (isX(fp))
from = '>=' + fM + '.' + fm + '.0';
else
from = '>=' + from;
if (isX(tM)) {
to = ''
} else if (isX(tm)) {
to = '<' + (+tM + 1) + '.0.0'
} else if (isX(tp)) {
to = '<' + tM + '.' + (+tm + 1) + '.0'
} else if (tpr) {
to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr
} else {
to = '<=' + to
}
if (isX(tM))
to = '';
else if (isX(tm))
to = '<' + (+tM + 1) + '.0.0';
else if (isX(tp))
to = '<' + tM + '.' + (+tm + 1) + '.0';
else if (tpr)
to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
else
to = '<=' + to;
return (from + ' ' + to).trim();
return (from + ' ' + to).trim()
}
// if ANY of the sets match ALL of its comparators, then pass
Range.prototype.test = function(version) {
if (!version)
return false;
Range.prototype.test = function (version) {
if (!version) {
return false
}
if (typeof version === 'string')
version = new SemVer(version, this.options);
if (typeof version === 'string') {
version = new SemVer(version, this.options)
}
for (var i = 0; i < this.set.length; i++) {
if (testSet(this.set[i], version, this.options))
return true;
if (testSet(this.set[i], version, this.options)) {
return true
}
}
return false;
};
return false
}
function testSet(set, version, options) {
function testSet (set, version, options) {
for (var i = 0; i < set.length; i++) {
if (!set[i].test(version))
return false;
if (!set[i].test(version)) {
return false
}
}
if (!options)
options = {}
if (version.prerelease.length && !options.includePrerelease) {

@@ -1192,13 +1258,15 @@ // Find the set of versions that are allowed to have prereleases

// even though it's within the range set by the comparators.
for (var i = 0; i < set.length; i++) {
debug(set[i].semver);
if (set[i].semver === ANY)
continue;
for (i = 0; i < set.length; i++) {
debug(set[i].semver)
if (set[i].semver === ANY) {
continue
}
if (set[i].semver.prerelease.length > 0) {
var allowed = set[i].semver;
var allowed = set[i].semver
if (allowed.major === version.major &&
allowed.minor === version.minor &&
allowed.patch === version.patch)
return true;
allowed.patch === version.patch) {
return true
}
}

@@ -1208,66 +1276,124 @@ }

// Version has a -pre, but it's not one of the ones we like.
return false;
return false
}
return true;
return true
}
exports.satisfies = satisfies;
function satisfies(version, range, options) {
exports.satisfies = satisfies
function satisfies (version, range, options) {
try {
range = new Range(range, options);
range = new Range(range, options)
} catch (er) {
return false;
return false
}
return range.test(version);
return range.test(version)
}
exports.maxSatisfying = maxSatisfying;
function maxSatisfying(versions, range, options) {
var max = null;
var maxSV = null;
exports.maxSatisfying = maxSatisfying
function maxSatisfying (versions, range, options) {
var max = null
var maxSV = null
try {
var rangeObj = new Range(range, options);
var rangeObj = new Range(range, options)
} catch (er) {
return null;
return null
}
versions.forEach(function (v) {
if (rangeObj.test(v)) { // satisfies(v, range, options)
if (!max || maxSV.compare(v) === -1) { // compare(max, v, true)
max = v;
maxSV = new SemVer(max, options);
if (rangeObj.test(v)) {
// satisfies(v, range, options)
if (!max || maxSV.compare(v) === -1) {
// compare(max, v, true)
max = v
maxSV = new SemVer(max, options)
}
}
})
return max;
return max
}
exports.minSatisfying = minSatisfying;
function minSatisfying(versions, range, options) {
var min = null;
var minSV = null;
exports.minSatisfying = minSatisfying
function minSatisfying (versions, range, options) {
var min = null
var minSV = null
try {
var rangeObj = new Range(range, options);
var rangeObj = new Range(range, options)
} catch (er) {
return null;
return null
}
versions.forEach(function (v) {
if (rangeObj.test(v)) { // satisfies(v, range, options)
if (!min || minSV.compare(v) === 1) { // compare(min, v, true)
min = v;
minSV = new SemVer(min, options);
if (rangeObj.test(v)) {
// satisfies(v, range, options)
if (!min || minSV.compare(v) === 1) {
// compare(min, v, true)
min = v
minSV = new SemVer(min, options)
}
}
})
return min;
return min
}
exports.validRange = validRange;
function validRange(range, options) {
exports.minVersion = minVersion
function minVersion (range, loose) {
range = new Range(range, loose)
var minver = new SemVer('0.0.0')
if (range.test(minver)) {
return minver
}
minver = new SemVer('0.0.0-0')
if (range.test(minver)) {
return minver
}
minver = null
for (var i = 0; i < range.set.length; ++i) {
var comparators = range.set[i]
comparators.forEach(function (comparator) {
// Clone to avoid manipulating the comparator's semver object.
var compver = new SemVer(comparator.semver.version)
switch (comparator.operator) {
case '>':
if (compver.prerelease.length === 0) {
compver.patch++
} else {
compver.prerelease.push(0)
}
compver.raw = compver.format()
/* fallthrough */
case '':
case '>=':
if (!minver || gt(minver, compver)) {
minver = compver
}
break
case '<':
case '<=':
/* Ignore maximum versions */
break
/* istanbul ignore next */
default:
throw new Error('Unexpected operation: ' + comparator.operator)
}
})
}
if (minver && range.test(minver)) {
return minver
}
return null
}
exports.validRange = validRange
function validRange (range, options) {
try {
// Return '*' instead of '' so that truthiness works.
// This will throw if it's invalid anyway
return new Range(range, options).range || '*';
return new Range(range, options).range || '*'
} catch (er) {
return null;
return null
}

@@ -1277,36 +1403,36 @@ }

// Determine if version is less than all the versions possible in the range
exports.ltr = ltr;
function ltr(version, range, options) {
return outside(version, range, '<', options);
exports.ltr = ltr
function ltr (version, range, options) {
return outside(version, range, '<', options)
}
// Determine if version is greater than all the versions possible in the range.
exports.gtr = gtr;
function gtr(version, range, options) {
return outside(version, range, '>', options);
exports.gtr = gtr
function gtr (version, range, options) {
return outside(version, range, '>', options)
}
exports.outside = outside;
function outside(version, range, hilo, options) {
version = new SemVer(version, options);
range = new Range(range, options);
exports.outside = outside
function outside (version, range, hilo, options) {
version = new SemVer(version, options)
range = new Range(range, options)
var gtfn, ltefn, ltfn, comp, ecomp;
var gtfn, ltefn, ltfn, comp, ecomp
switch (hilo) {
case '>':
gtfn = gt;
ltefn = lte;
ltfn = lt;
comp = '>';
ecomp = '>=';
break;
gtfn = gt
ltefn = lte
ltfn = lt
comp = '>'
ecomp = '>='
break
case '<':
gtfn = lt;
ltefn = gte;
ltfn = gt;
comp = '<';
ecomp = '<=';
break;
gtfn = lt
ltefn = gte
ltfn = gt
comp = '<'
ecomp = '<='
break
default:
throw new TypeError('Must provide a hilo val of "<" or ">"');
throw new TypeError('Must provide a hilo val of "<" or ">"')
}

@@ -1316,3 +1442,3 @@

if (satisfies(version, range, options)) {
return false;
return false
}

@@ -1324,19 +1450,19 @@

for (var i = 0; i < range.set.length; ++i) {
var comparators = range.set[i];
var comparators = range.set[i]
var high = null;
var low = null;
var high = null
var low = null
comparators.forEach(function(comparator) {
comparators.forEach(function (comparator) {
if (comparator.semver === ANY) {
comparator = new Comparator('>=0.0.0')
}
high = high || comparator;
low = low || comparator;
high = high || comparator
low = low || comparator
if (gtfn(comparator.semver, high.semver, options)) {
high = comparator;
high = comparator
} else if (ltfn(comparator.semver, low.semver, options)) {
low = comparator;
low = comparator
}
});
})

@@ -1346,3 +1472,3 @@ // If the edge version comparator has a operator then our version

if (high.operator === comp || high.operator === ecomp) {
return false;
return false
}

@@ -1354,18 +1480,18 @@

ltefn(version, low.semver)) {
return false;
return false
} else if (low.operator === ecomp && ltfn(version, low.semver)) {
return false;
return false
}
}
return true;
return true
}
exports.prerelease = prerelease;
function prerelease(version, options) {
var parsed = parse(version, options);
return (parsed && parsed.prerelease.length) ? parsed.prerelease : null;
exports.prerelease = prerelease
function prerelease (version, options) {
var parsed = parse(version, options)
return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
}
exports.intersects = intersects;
function intersects(r1, r2, options) {
exports.intersects = intersects
function intersects (r1, r2, options) {
r1 = new Range(r1, options)

@@ -1376,16 +1502,21 @@ r2 = new Range(r2, options)

exports.coerce = coerce;
function coerce(version) {
if (version instanceof SemVer)
return version;
exports.coerce = coerce
function coerce (version) {
if (version instanceof SemVer) {
return version
}
if (typeof version !== 'string')
return null;
if (typeof version !== 'string') {
return null
}
var match = version.match(re[COERCE]);
var match = version.match(re[COERCE])
if (match == null)
return null;
if (match == null) {
return null
}
return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
return parse(match[1] +
'.' + (match[2] || '0') +
'.' + (match[3] || '0'))
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc