semver-compare-range
v0.0.3
Published
Compare two semver version or version range strings.
Downloads
23
Readme
semver compare
Compare two semver version or version range strings, returning -1,0,1. To be used by passing into [].sort()
. Developed to order versioned sql files to ensure proper order of execution.
Example
var cmp = require('semver-compare-range');
var versions = [
'1.0.0',
'0.0.1 - 0.0.9',
'1.1.0 - 1.1.0',
'0.0.0 - 0.0.1',
'0.0.0',
'0.0.9 - 1.0.0',
];
console.log(versions.sort(cmp).join('\n'));
Example Return
0.0.0
0.0.0 - 0.0.1
0.0.1 - 0.0.9
0.0.9 - 1.0.0
1.0.0
1.0.0 - 1.1.0
Methods
var cmp = require('semver-compare-range');
cmp(a,b)
*
or(empty string)
will return-1
.- Invalid version will return
0
. a < b
return-1
;a == b
return0
;a > b
return1
.- When
a
is not a version range andb
is a version range:a <= min(b)
return-1
;a > min(b)
return1
. - When
a
andb
are version ranges:min(a) < min(b)
return-1
;min(a) > min(b)
return1
;min(a) == min(b) && max(a) < max(b)
return-1
;min(a) == min(b) && max(a) > max(b)
return1
;a == b
return0
.
Install
npm install semver-compare-range
License
MIT