allow 'v' prefix, implemented missing 'stringifyRange'
This commit is contained in:
parent
9dd782e51d
commit
d1a4afb909
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "semver-utils",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"description": "Tools for manipulating semver strings and objects",
|
||||
"main": "semver-utils.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -1,17 +1,39 @@
|
|||
(function () {
|
||||
var semverutils = require('semver-utils')
|
||||
var semverutils = require('./semver-utils')
|
||||
;
|
||||
|
||||
function testParseRange() {
|
||||
var str = '~1.0.0 || >= 1.1.7 < 2.0.0+build.1848 || v1.1.3 || 2.0.1-alpha.1227 || 1.0.0 - 1.0.x'
|
||||
console.info('testParseRange');
|
||||
var good =
|
||||
[ 'v1.0.0'
|
||||
, '< v2.0.0'
|
||||
, '~v2.0.0'
|
||||
, '~1.0.0'
|
||||
, '~1.0.0 || >= 1.1.7 < 2.0.0+build.1848'
|
||||
, '~1.0.0 || >= 1.1.7 < 2.0.0+build.1848 || v1.1.3'
|
||||
, '~1.0.0 || >= 1.1.7 < 2.0.0+build.1848 || v1.1.3 || 2.0.1-alpha.1227'
|
||||
, '~1.0.0 || >= 1.1.7 < 2.0.0+build.1848 || v1.1.3 || 2.0.1-alpha.1227 || 1.0.0 - 1.0.x'
|
||||
, '~1.0.0 || >= 1.1.7 < 2.0.0+build.1848 || v1.1.3 || 2.0.1-alpha.1227 || 1.0.0 - 1.0.x || 1.*'
|
||||
]
|
||||
;
|
||||
console.log(semverutils.parseRange(str));
|
||||
console.log(semverutils.parseRange('v1.0.0'));
|
||||
console.log(semverutils.parseRange('< v2.0.0'));
|
||||
console.log(semverutils.parseRange('~v2.0.0'));
|
||||
|
||||
good.every(function (range) {
|
||||
var result = semverutils.parseRange(range)
|
||||
;
|
||||
|
||||
if (!result || 0 === result.length) {
|
||||
throw new Error("didn't parse something that should be parseable: " + range);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
console.log(good[good.length - 1]);
|
||||
console.log(semverutils.stringifyRange(semverutils.parseRange(good[good.length - 1])));
|
||||
}
|
||||
|
||||
function testParse() {
|
||||
console.info('testParse');
|
||||
var good
|
||||
, bad
|
||||
;
|
||||
|
@ -43,7 +65,7 @@
|
|||
];
|
||||
|
||||
bad = [
|
||||
"v1.0.0"
|
||||
// "v1.0.0" now allows optional 'v'
|
||||
, "a.b.c"
|
||||
, "1"
|
||||
, "1.0.0b"
|
|
@ -1,8 +1,14 @@
|
|||
(function () {
|
||||
"use strict";
|
||||
|
||||
var reSemver = /^((\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
|
||||
// TODO break these down into escaped strings with meaningful comments and create using new RegExp()
|
||||
// |optional 'v'
|
||||
// | | 3 segment version
|
||||
// | | |optional release prefixed by '-'
|
||||
// | | | |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
|
||||
;
|
||||
|
||||
function parseSemver(version) {
|
||||
|
@ -83,7 +89,24 @@
|
|||
return arr;
|
||||
}
|
||||
|
||||
function stringifySemverRange(arr) {
|
||||
var str = ''
|
||||
;
|
||||
|
||||
arr.forEach(function (ver) {
|
||||
if (ver.operator) {
|
||||
str += ver.operator + ' ';
|
||||
}
|
||||
if (ver.major) {
|
||||
str += stringifySemver(ver) + ' ';
|
||||
}
|
||||
});
|
||||
|
||||
return str.trim();
|
||||
}
|
||||
|
||||
module.exports.parse = parseSemver;
|
||||
module.exports.stringify = stringifySemver;
|
||||
module.exports.parseRange = parseSemverRange;
|
||||
module.exports.stringifyRange = stringifySemverRange;
|
||||
}());
|
||||
|
|
Loading…
Reference in New Issue