Compare version strings according to Semantic Versioning 2.0.0
const semverCompare = require('semantic-compare');
console.log([
'1.0.0-alpha.1',
'1.0.0-beta',
'1.0.0',
'1.0.0-alpha.beta',
'1.0.0-rc.1',
'1.0.0-beta.2',
'1.0.0-alpha',
'1.0.0-beta.11'
].sort(semverCompare));
Output:
[ '1.0.0-alpha',
'1.0.0-alpha.1',
'1.0.0-alpha.beta',
'1.0.0-beta',
'1.0.0-beta.2',
'1.0.0-beta.11',
'1.0.0-rc.1',
'1.0.0' ]
MIT (c) Sebastian Raff