compare-versions
Advanced tools
Comparing version 2.0.2 to 3.0.0
{ | ||
"name": "compare-versions", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "Compare semver version strings to find greater, equal or lesser.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
12
index.js
@@ -13,2 +13,3 @@ /* global define */ | ||
var semver = /^v?(?:0|[1-9]\d*)(\.(?:[x*]|0|[1-9]\d*)(\.(?:[x*]|0|[1-9]\d*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i; | ||
var patch = /-([0-9A-Za-z-.]+)/; | ||
@@ -27,3 +28,14 @@ | ||
function validate(version) { | ||
if (typeof version !== 'string') { | ||
throw new TypeError('Invalid argument expected string'); | ||
} | ||
if (!semver.test(version)) { | ||
throw new Error('Invalid argument not valid semver'); | ||
} | ||
} | ||
return function compareVersions(v1, v2) { | ||
[v1, v2].forEach(validate); | ||
var s1 = split(v1); | ||
@@ -30,0 +42,0 @@ var s2 = split(v2); |
{ | ||
"name": "compare-versions", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "Compare semver version strings to find greater, equal or lesser.", | ||
@@ -26,4 +26,4 @@ "main": "index.js", | ||
"istanbul": "^0.4.3", | ||
"mocha": "^2.5.3" | ||
"mocha": "^3.0.2" | ||
} | ||
} |
@@ -8,3 +8,3 @@ # compare-versions | ||
This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`. | ||
This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`. Also supports wildcards for minor and patch version like `1.0.x` or `1.0.*`. | ||
@@ -11,0 +11,0 @@ ## Install |
@@ -45,2 +45,3 @@ var assert = require('assert'); | ||
[ | ||
['1.0.0-alpha.1', '1.0.0-alpha', 1], | ||
['1.0.0-alpha', '1.0.0-alpha.1', -1], | ||
@@ -65,2 +66,16 @@ ['1.0.0-alpha.1', '1.0.0-alpha.beta', -1], | ||
}); | ||
it('should throw on invalid input', function () { | ||
[ | ||
[42, /Invalid argument expected string/], | ||
[{}, /Invalid argument expected string/], | ||
[[], /Invalid argument expected string/], | ||
[function () {}, /Invalid argument expected string/], | ||
['6.3.', /Invalid argument not valid semver/], | ||
].forEach(function (data) { | ||
assert.throws(function () { | ||
compare(data[0], data[0]); | ||
}, data[1]); | ||
}); | ||
}); | ||
}); |
@@ -13,3 +13,3 @@ var assert = require('assert'); | ||
['0.7.x', '0.7.0-asdf'], | ||
['1', '0.0.0beta'], | ||
['1', '0.0.0-beta'], | ||
['1', '0.2.3'], | ||
@@ -16,0 +16,0 @@ ['1', '0.2.4'], |
Sorry, the diff of this file is not supported yet
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
12054
11
260