|
|
||||
|---|---|---|---|---|
| .. | ||||
| test | 11e3a9652a | 7 anni fa | ||
| .editorconfig | 11e3a9652a | 7 anni fa | ||
| .npmignore | 11e3a9652a | 7 anni fa | ||
| .travis.yml | 11e3a9652a | 7 anni fa | ||
| CHANGELOG.md | 11e3a9652a | 7 anni fa | ||
| LICENSE | 11e3a9652a | 7 anni fa | ||
| README.md | 11e3a9652a | 7 anni fa | ||
| bower.json | 11e3a9652a | 7 anni fa | ||
| index.js | 11e3a9652a | 7 anni fa | ||
| package.json | 11e3a9652a | 7 anni fa | ||
Compare semver version strings to find greater, equal or lesser. Runs in the browser as well as Node.js/React Native etc. Has no dependencies and is tiny (<600 bytes gzipped).
This library supports the full semver specification, including comparing versions with different number of digits like 1.0.0, 1.0, 1, and pre-release versions like 1.0.0-alpha. Also supports wildcards for minor and patch version like 1.0.x or 1.0.*. Any leading v is ignored. Numbers with leading zero is handled as normal numbers ignoring the zero.
Install with npm or bower:
$ npm install compare-versions --save
$ bower install compare-versions --save
var compareVersions = require('compare-versions');
compareVersions('10.1.8', '10.0.4'); // 1
compareVersions('10.0.1', '10.0.1'); // 0
compareVersions('10.1.1', '10.2.2'); // -1
Can also be used for sorting:
var versions = [
'1.5.19',
'1.2.3',
'1.5.5'
];
console.log(versions.sort(compareVersions));
Outputs:
[
'1.2.3',
'1.5.5',
'1.5.19'
]