semiver
A tiny (187B) utility to compare semver strings.
Compare semver strings (eg, 1.8.2
, 2.0.0-next.6
, 0.0.0-alpha-1
, etc) using the Intl.Collator
class.
Version suffixes are supported and are considered during comparison.
The output will always be 0
, 1
, or -1
, allowing semiver
to be used directly as a compare function for Array.sort()
.
This module exposes three module definitions:
- ES Module:
dist/semiver.mjs
- CommonJS:
dist/semiver.js
- UMD:
dist/semiver.min.js
Install
$ npm install --save semiver
Usage
; // A === B; //=> 0; //=> 0 // A > B; //=> 1; //=> 1; //=> 1; //=> 1; //=> 1; //=> 1; //=> 1 // A < B; //=> -1; //=> -1; //=> -1; //=> -1; //=> -1; //=> -1; //=> -1 // Sorting '4.11.6' '4.2.0' '1.5.19' '1.5.5' '1.0.0' '1.0.0-rc.1' '1.2.3' '1.2.3-alpha' '1.0.0-alpha.1' '1.0.0-alpha' '1.0.0-beta.11' '1.0.0-beta';/* [ '1.0.0-alpha', '1.0.0-alpha.1', '1.0.0-beta', '1.0.0-beta.11', '1.0.0-rc.1', '1.0.0', '1.2.3-alpha', '1.2.3', '1.5.5', '1.5.19', '4.2.0', '4.11.6' ]*/
API
semiver(a, b)
Returns: Number
0
indicates thata
is equal tob
-1
indicates thata
is less thanb
1
indicates thata
is greater thanb
a
Type: String
The input string to compare.
b
Type: String
The string to compare against.
License
MIT © Luke Edwards