From 74cc0b238e6cfb98238b290022f9c9ca1692e3dc Mon Sep 17 00:00:00 2001 From: metaraine Date: Sat, 6 Jun 2015 15:27:43 -0600 Subject: [PATCH] Add support for caret (^) --- semver-utils.js | 9 ++------- test/spec.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/semver-utils.js b/semver-utils.js index 3f6c143..994239f 100644 --- a/semver-utils.js +++ b/semver-utils.js @@ -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] diff --git a/test/spec.js b/test/spec.js index 76a37a9..0417f17 100644 --- a/test/spec.js +++ b/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() { deepOwnEqual(semverutils.parseRange('~v1.0.0'), [{ semver: '~v1.0.0',