Add support for caret (^)

This commit is contained in:
metaraine 2015-06-06 15:27:43 -06:00
parent d9e4e7b776
commit 74cc0b238e
2 changed files with 12 additions and 7 deletions

View File

@ -8,7 +8,7 @@
// | | | |optional build prefixed by '+'
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
;
// Returns a new object with all of the undefined properties removed from the given object
@ -22,7 +22,6 @@
return o;
}
function stringifySemver(obj) {
var str = ''
;
@ -123,11 +122,7 @@
;
while (true) {
m = reSemverRange.exec(str);
if (!m) {
break;
}
while (m = reSemverRange.exec(str)) {
obj = {
semver: m[3]
, operator: m[4] || m[2]

View File

@ -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() {
deepOwnEqual(semverutils.parseRange('~v1.0.0'), [{
semver: '~v1.0.0',