Compare semver version strings to find which is greater, equal or lesser.
JavaScript
Latest commit f07d229 Aug 10, 2016 @omichelsen Add changelog.

README.md

compare-versions

Build Status Coverage Status

Compare semver version strings to find greater, equal or lesser. Runs in the browser as well as node.js/iojs.

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.*.

Install

Install with npm or bower:

$ npm install compare-versions --save
$ bower install compare-versions --save

Usage

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'
]