Skip to content

Latest commit

 

History

History
51 lines (37 loc) · 1.22 KB

README.md

File metadata and controls

51 lines (37 loc) · 1.22 KB

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.

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