Add support for caret (^)
This commit is contained in:
parent
d9e4e7b776
commit
74cc0b238e
|
@ -8,7 +8,7 @@
|
||||||
// | | | |optional build prefixed by '+'
|
// | | | |optional build prefixed by '+'
|
||||||
var reSemver = /^v?((\d+)\.(\d+)\.(\d+))(?:-([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?(?:\+([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?$/
|
var reSemver = /^v?((\d+)\.(\d+)\.(\d+))(?:-([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?(?:\+([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?$/
|
||||||
//, reSemverRange = /\s*((\|\||\-)|(([<>~]?=?)\s*(v)?([0-9]+)(\.(x|[0-9]+))?(\.(x|[0-9]+))?(([\-+])([a-zA-Z0-9\.]+))?))\s*/g
|
//, reSemverRange = /\s*((\|\||\-)|(([<>~]?=?)\s*(v)?([0-9]+)(\.(x|[0-9]+))?(\.(x|[0-9]+))?(([\-+])([a-zA-Z0-9\.]+))?))\s*/g
|
||||||
, reSemverRange = /\s*((\|\||\-)|(([<>~]?=?)\s*(v)?([0-9]+)(\.(x|\*|[0-9]+))?(\.(x|\*|[0-9]+))?(([\-+])([a-zA-Z0-9\.]+))?))\s*/g
|
, reSemverRange = /\s*((\|\||\-)|(([<>~^]?=?)\s*(v)?([0-9]+)(\.(x|\*|[0-9]+))?(\.(x|\*|[0-9]+))?(([\-+])([a-zA-Z0-9\.]+))?))\s*/g
|
||||||
;
|
;
|
||||||
|
|
||||||
// Returns a new object with all of the undefined properties removed from the given object
|
// Returns a new object with all of the undefined properties removed from the given object
|
||||||
|
@ -22,7 +22,6 @@
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function stringifySemver(obj) {
|
function stringifySemver(obj) {
|
||||||
var str = ''
|
var str = ''
|
||||||
;
|
;
|
||||||
|
@ -123,11 +122,7 @@
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
while (true) {
|
while (m = reSemverRange.exec(str)) {
|
||||||
m = reSemverRange.exec(str);
|
|
||||||
if (!m) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
obj = {
|
obj = {
|
||||||
semver: m[3]
|
semver: m[3]
|
||||||
, operator: m[4] || m[2]
|
, operator: m[4] || m[2]
|
||||||
|
|
10
test/spec.js
10
test/spec.js
|
@ -88,6 +88,16 @@ describe('parseRange', function() {
|
||||||
}]);
|
}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should parse caret', function() {
|
||||||
|
deepOwnEqual(semverutils.parseRange('^1.0.0'), [{
|
||||||
|
semver: '^1.0.0',
|
||||||
|
operator: '^',
|
||||||
|
major: '1',
|
||||||
|
minor: '0',
|
||||||
|
patch: '0'
|
||||||
|
}]);
|
||||||
|
});
|
||||||
|
|
||||||
it('should parse tilde and v- prefix', function() {
|
it('should parse tilde and v- prefix', function() {
|
||||||
deepOwnEqual(semverutils.parseRange('~v1.0.0'), [{
|
deepOwnEqual(semverutils.parseRange('~v1.0.0'), [{
|
||||||
semver: '~v1.0.0',
|
semver: '~v1.0.0',
|
||||||
|
|
Loading…
Reference in New Issue