version-sort
v0.1.1
Published
Sort an array of versions.
Downloads
9,990
Readme
version-sort
Sort an array of versions.
Usage
This module sort an array of versions. Here some examples of valid versions:
1.1.0
1.1.4
1.1.4.469816
2.4
2.4.2
2.4.20
2.4.20alpha
2.4.20beta
2.4.20rc1
2.4.20rc2
To use it just call the module as a function.
var sort = require('version-sort');
data = [ '2.4.20', '2.4.20rc1', '1.1', '2.4.20beta1' ];
sort(data); // '1.1', '2.4.20beta1', '2.4.20rc1', '2.4.20'
Options
var results = sort(data, options);
ignore_stages
: (default:false
) Only return stables versions and ignore staged versions. Example:var results = sort([ '1.1', '1.1alpha' ], { ignore_stages: true }); // [ '1.1' ]
nested
: (default:false
) Use this option to sort object by a field. Example:var softwares = [ { version: '1.1' }, { version: '1.1alpha' } ]; var results = sort(softwares, { nested: 'version' }); // [ { version: '1.1alpha' }, { version: '1.1'} ]
Installation
npm install --save version-sort