Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.5.1 to 5.6.0

2

package.json
{
"name": "semver",
"version": "5.5.1",
"version": "5.6.0",
"description": "The semantic version parser used by npm.",

@@ -5,0 +5,0 @@ "main": "semver.js",

@@ -32,4 +32,2 @@ semver(1) -- The semantic versioner for npm

SemVer 5.3.0
A JavaScript implementation of the http://semver.org/ specification

@@ -58,2 +56,5 @@ Copyright Isaac Z. Schlueter

-p --include-prerelease
Always include prerelease versions in range matching
-c --coerce

@@ -294,6 +295,16 @@ Coerce a string into SemVer if possible

All methods and classes take a final `loose` boolean argument that, if
true, will be more forgiving about not-quite-valid semver strings.
The resulting output will always be 100% strict, of course.
All methods and classes take a final `options` object argument. All
options in this object are `false` by default. The options supported
are:
- `loose` Be more forgiving about not-quite-valid semver strings.
(Any resulting output will always be 100% strict compliant, of
course.) For backwards compatibility reasons, if the `options`
argument is a boolean value instead of an object, it is interpreted
to be the `loose` param.
- `includePrerelease` Set to suppress the [default
behavior](https://github.com/npm/node-semver#prerelease-tags) of
excluding prerelease tagged versions from ranges unless they are
explicitly opted into.
Strict-mode Comparators and Ranges will be strict about the SemVer

@@ -300,0 +311,0 @@ strings that they parse.

@@ -248,3 +248,6 @@ exports = module.exports = SemVer;

exports.parse = parse;
function parse(version, loose) {
function parse(version, options) {
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
if (version instanceof SemVer)

@@ -259,3 +262,3 @@ return version;

var r = loose ? re[LOOSE] : re[FULL];
var r = options.loose ? re[LOOSE] : re[FULL];
if (!r.test(version))

@@ -265,3 +268,3 @@ return null;

try {
return new SemVer(version, loose);
return new SemVer(version, options);
} catch (er) {

@@ -273,4 +276,4 @@ return null;

exports.valid = valid;
function valid(version, loose) {
var v = parse(version, loose);
function valid(version, options) {
var v = parse(version, options);
return v ? v.version : null;

@@ -281,4 +284,4 @@ }

exports.clean = clean;
function clean(version, loose) {
var s = parse(version.trim().replace(/^[=v]+/, ''), loose);
function clean(version, options) {
var s = parse(version.trim().replace(/^[=v]+/, ''), options);
return s ? s.version : null;

@@ -289,5 +292,7 @@ }

function SemVer(version, loose) {
function SemVer(version, options) {
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
if (version instanceof SemVer) {
if (version.loose === loose)
if (version.loose === options.loose)
return version;

@@ -304,8 +309,10 @@ else

if (!(this instanceof SemVer))
return new SemVer(version, loose);
return new SemVer(version, options);
debug('SemVer', version, loose);
this.loose = loose;
var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
debug('SemVer', version, options);
this.options = options;
this.loose = !!options.loose;
var m = version.trim().match(options.loose ? re[LOOSE] : re[FULL]);
if (!m)

@@ -359,5 +366,5 @@ throw new TypeError('Invalid Version: ' + version);

SemVer.prototype.compare = function(other) {
debug('SemVer.compare', this.version, this.loose, other);
debug('SemVer.compare', this.version, this.options, other);
if (!(other instanceof SemVer))
other = new SemVer(other, this.loose);
other = new SemVer(other, this.options);

@@ -369,3 +376,3 @@ return this.compareMain(other) || this.comparePre(other);

if (!(other instanceof SemVer))
other = new SemVer(other, this.loose);
other = new SemVer(other, this.options);

@@ -379,3 +386,3 @@ return compareIdentifiers(this.major, other.major) ||

if (!(other instanceof SemVer))
other = new SemVer(other, this.loose);
other = new SemVer(other, this.options);

@@ -671,5 +678,8 @@ // NOT having a prerelease is > having one

exports.Comparator = Comparator;
function Comparator(comp, loose) {
function Comparator(comp, options) {
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
if (comp instanceof Comparator) {
if (comp.loose === loose)
if (comp.loose === !!options.loose)
return comp;

@@ -681,6 +691,7 @@ else

if (!(this instanceof Comparator))
return new Comparator(comp, loose);
return new Comparator(comp, options);
debug('comparator', comp, loose);
this.loose = loose;
debug('comparator', comp, options);
this.options = options;
this.loose = !!options.loose;
this.parse(comp);

@@ -698,3 +709,3 @@

Comparator.prototype.parse = function(comp) {
var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
var r = this.options.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
var m = comp.match(r);

@@ -713,3 +724,3 @@

else
this.semver = new SemVer(m[2], this.loose);
this.semver = new SemVer(m[2], this.options.loose);
};

@@ -722,3 +733,3 @@

Comparator.prototype.test = function(version) {
debug('Comparator.test', version, this.loose);
debug('Comparator.test', version, this.options.loose);

@@ -729,8 +740,8 @@ if (this.semver === ANY)

if (typeof version === 'string')
version = new SemVer(version, this.loose);
version = new SemVer(version, this.options);
return cmp(version, this.operator, this.semver, this.loose);
return cmp(version, this.operator, this.semver, this.options);
};
Comparator.prototype.intersects = function(comp, loose) {
Comparator.prototype.intersects = function(comp, options) {
if (!(comp instanceof Comparator)) {

@@ -740,10 +751,13 @@ throw new TypeError('a Comparator is required');

if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
var rangeTmp;
if (this.operator === '') {
rangeTmp = new Range(comp.value, loose);
return satisfies(this.value, rangeTmp, loose);
rangeTmp = new Range(comp.value, options);
return satisfies(this.value, rangeTmp, options);
} else if (comp.operator === '') {
rangeTmp = new Range(this.value, loose);
return satisfies(comp.semver, rangeTmp, loose);
rangeTmp = new Range(this.value, options);
return satisfies(comp.semver, rangeTmp, options);
}

@@ -762,7 +776,7 @@

var oppositeDirectionsLessThan =
cmp(this.semver, '<', comp.semver, loose) &&
cmp(this.semver, '<', comp.semver, options) &&
((this.operator === '>=' || this.operator === '>') &&
(comp.operator === '<=' || comp.operator === '<'));
var oppositeDirectionsGreaterThan =
cmp(this.semver, '>', comp.semver, loose) &&
cmp(this.semver, '>', comp.semver, options) &&
((this.operator === '<=' || this.operator === '<') &&

@@ -778,8 +792,12 @@ (comp.operator === '>=' || comp.operator === '>'));

exports.Range = Range;
function Range(range, loose) {
function Range(range, options) {
if (!options || typeof options !== 'object')
options = { loose: !!options, includePrerelease: false }
if (range instanceof Range) {
if (range.loose === loose) {
if (range.loose === !!options.loose &&
range.includePrerelease === !!options.includePrerelease) {
return range;
} else {
return new Range(range.raw, loose);
return new Range(range.raw, options);
}

@@ -789,9 +807,11 @@ }

if (range instanceof Comparator) {
return new Range(range.value, loose);
return new Range(range.value, options);
}
if (!(this instanceof Range))
return new Range(range, loose);
return new Range(range, options);
this.loose = loose;
this.options = options;
this.loose = !!options.loose;
this.includePrerelease = !!options.includePrerelease

@@ -826,5 +846,4 @@ // First, split based on boolean or ||

Range.prototype.parseRange = function(range) {
var loose = this.loose;
var loose = this.options.loose;
range = range.trim();
debug('range', range, loose);
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`

@@ -852,5 +871,5 @@ var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];

var set = range.split(' ').map(function(comp) {
return parseComparator(comp, loose);
}).join(' ').split(/\s+/);
if (this.loose) {
return parseComparator(comp, this.options);
}, this).join(' ').split(/\s+/);
if (this.options.loose) {
// in loose mode, throw out any that are not valid comparators

@@ -862,4 +881,4 @@ set = set.filter(function(comp) {

set = set.map(function(comp) {
return new Comparator(comp, loose);
});
return new Comparator(comp, this.options);
}, this);

@@ -869,3 +888,3 @@ return set;

Range.prototype.intersects = function(range, loose) {
Range.prototype.intersects = function(range, options) {
if (!(range instanceof Range)) {

@@ -879,3 +898,3 @@ throw new TypeError('a Range is required');

return rangeComparators.every(function(rangeComparator) {
return thisComparator.intersects(rangeComparator, loose);
return thisComparator.intersects(rangeComparator, options);
});

@@ -889,4 +908,4 @@ });

exports.toComparators = toComparators;
function toComparators(range, loose) {
return new Range(range, loose).set.map(function(comp) {
function toComparators(range, options) {
return new Range(range, options).set.map(function(comp) {
return comp.map(function(c) {

@@ -901,11 +920,11 @@ return c.value;

// turn into a set of JUST comparators.
function parseComparator(comp, loose) {
debug('comp', comp);
comp = replaceCarets(comp, loose);
function parseComparator(comp, options) {
debug('comp', comp, options);
comp = replaceCarets(comp, options);
debug('caret', comp);
comp = replaceTildes(comp, loose);
comp = replaceTildes(comp, options);
debug('tildes', comp);
comp = replaceXRanges(comp, loose);
comp = replaceXRanges(comp, options);
debug('xrange', comp);
comp = replaceStars(comp, loose);
comp = replaceStars(comp, options);
debug('stars', comp);

@@ -925,10 +944,12 @@ return comp;

// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
function replaceTildes(comp, loose) {
function replaceTildes(comp, options) {
return comp.trim().split(/\s+/).map(function(comp) {
return replaceTilde(comp, loose);
return replaceTilde(comp, options);
}).join(' ');
}
function replaceTilde(comp, loose) {
var r = loose ? re[TILDELOOSE] : re[TILDE];
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) {

@@ -967,11 +988,13 @@ debug('tilde', comp, _, M, m, p, pr);

// ^1.2.0 --> >=1.2.0 <2.0.0
function replaceCarets(comp, loose) {
function replaceCarets(comp, options) {
return comp.trim().split(/\s+/).map(function(comp) {
return replaceCaret(comp, loose);
return replaceCaret(comp, options);
}).join(' ');
}
function replaceCaret(comp, loose) {
debug('caret', comp, loose);
var r = loose ? re[CARETLOOSE] : re[CARET];
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) {

@@ -1023,12 +1046,14 @@ debug('caret', comp, _, M, m, p, pr);

function replaceXRanges(comp, loose) {
debug('replaceXRanges', comp, loose);
function replaceXRanges(comp, options) {
debug('replaceXRanges', comp, options);
return comp.split(/\s+/).map(function(comp) {
return replaceXRange(comp, loose);
return replaceXRange(comp, options);
}).join(' ');
}
function replaceXRange(comp, loose) {
function replaceXRange(comp, options) {
comp = comp.trim();
var r = loose ? re[XRANGELOOSE] : re[XRANGE];
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) {

@@ -1097,4 +1122,4 @@ debug('xRange', comp, ret, gtlt, M, m, p, pr);

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

@@ -1143,6 +1168,6 @@ return comp.trim().replace(re[STAR], '');

if (typeof version === 'string')
version = new SemVer(version, this.loose);
version = new SemVer(version, this.options);
for (var i = 0; i < this.set.length; i++) {
if (testSet(this.set[i], version))
if (testSet(this.set[i], version, this.options))
return true;

@@ -1153,3 +1178,3 @@ }

function testSet(set, version) {
function testSet(set, version, options) {
for (var i = 0; i < set.length; i++) {

@@ -1160,3 +1185,6 @@ if (!set[i].test(version))

if (version.prerelease.length) {
if (!options)
options = {}
if (version.prerelease.length && !options.includePrerelease) {
// Find the set of versions that are allowed to have prereleases

@@ -1189,5 +1217,5 @@ // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0

exports.satisfies = satisfies;
function satisfies(version, range, loose) {
function satisfies(version, range, options) {
try {
range = new Range(range, loose);
range = new Range(range, options);
} catch (er) {

@@ -1200,7 +1228,7 @@ return false;

exports.maxSatisfying = maxSatisfying;
function maxSatisfying(versions, range, loose) {
function maxSatisfying(versions, range, options) {
var max = null;
var maxSV = null;
try {
var rangeObj = new Range(range, loose);
var rangeObj = new Range(range, options);
} catch (er) {

@@ -1210,6 +1238,6 @@ return null;

versions.forEach(function (v) {
if (rangeObj.test(v)) { // satisfies(v, range, loose)
if (rangeObj.test(v)) { // satisfies(v, range, options)
if (!max || maxSV.compare(v) === -1) { // compare(max, v, true)
max = v;
maxSV = new SemVer(max, loose);
maxSV = new SemVer(max, options);
}

@@ -1222,7 +1250,7 @@ }

exports.minSatisfying = minSatisfying;
function minSatisfying(versions, range, loose) {
function minSatisfying(versions, range, options) {
var min = null;
var minSV = null;
try {
var rangeObj = new Range(range, loose);
var rangeObj = new Range(range, options);
} catch (er) {

@@ -1232,6 +1260,6 @@ return null;

versions.forEach(function (v) {
if (rangeObj.test(v)) { // satisfies(v, range, loose)
if (rangeObj.test(v)) { // satisfies(v, range, options)
if (!min || minSV.compare(v) === 1) { // compare(min, v, true)
min = v;
minSV = new SemVer(min, loose);
minSV = new SemVer(min, options);
}

@@ -1244,7 +1272,7 @@ }

exports.validRange = validRange;
function validRange(range, loose) {
function validRange(range, options) {
try {
// Return '*' instead of '' so that truthiness works.
// This will throw if it's invalid anyway
return new Range(range, loose).range || '*';
return new Range(range, options).range || '*';
} catch (er) {

@@ -1257,4 +1285,4 @@ return null;

exports.ltr = ltr;
function ltr(version, range, loose) {
return outside(version, range, '<', loose);
function ltr(version, range, options) {
return outside(version, range, '<', options);
}

@@ -1264,10 +1292,10 @@

exports.gtr = gtr;
function gtr(version, range, loose) {
return outside(version, range, '>', loose);
function gtr(version, range, options) {
return outside(version, range, '>', options);
}
exports.outside = outside;
function outside(version, range, hilo, loose) {
version = new SemVer(version, loose);
range = new Range(range, loose);
function outside(version, range, hilo, options) {
version = new SemVer(version, options);
range = new Range(range, options);

@@ -1295,3 +1323,3 @@ var gtfn, ltefn, ltfn, comp, ecomp;

// If it satisifes the range it is not outside
if (satisfies(version, range, loose)) {
if (satisfies(version, range, options)) {
return false;

@@ -1315,5 +1343,5 @@ }

low = low || comparator;
if (gtfn(comparator.semver, high.semver, loose)) {
if (gtfn(comparator.semver, high.semver, options)) {
high = comparator;
} else if (ltfn(comparator.semver, low.semver, loose)) {
} else if (ltfn(comparator.semver, low.semver, options)) {
low = comparator;

@@ -1342,4 +1370,4 @@ }

exports.prerelease = prerelease;
function prerelease(version, loose) {
var parsed = parse(version, loose);
function prerelease(version, options) {
var parsed = parse(version, options);
return (parsed && parsed.prerelease.length) ? parsed.prerelease : null;

@@ -1349,5 +1377,5 @@ }

exports.intersects = intersects;
function intersects(r1, r2, loose) {
r1 = new Range(r1, loose)
r2 = new Range(r2, loose)
function intersects(r1, r2, options) {
r1 = new Range(r1, options)
r2 = new Range(r2, options)
return r1.intersects(r2)

@@ -1354,0 +1382,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