semver-compare-range

Compare two semver version or version range strings.


Keywords
sort, semver, sort semver
License
MIT
Install
npm install semver-compare-range@0.0.3

Documentation

semver compare

Build Status Dependency Status Coverage Status

NPM

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 return 0; a > b return 1.
  • When a is not a version range and b is a version range: a <= min(b) return -1; a > min(b) return 1.
  • When a and b are version ranges: min(a) < min(b) return -1; min(a) > min(b) return 1; min(a) == min(b) && max(a) < max(b) return -1; min(a) == min(b) && max(a) > max(b) return 1; a == b return 0.

Install

npm install semver-compare-range

License

MIT