typewise-semver
Version:
Structure semver values as arrays which sort typewise with correct semver sort semantics
24 lines (20 loc) • 517 B
JavaScript
var semver = require('semver')
exports.parse = function (s) {
var v = typeof s === 'string' ? semver.parse(s) : s
var a = [ v.major, v.minor, v.patch ].concat(v.prerelease)
// if prerelease tag without associated version, sort first amonst tags
if (a[3] !== undefined && a[4] === undefined) {
a[4] = null
}
return a
}
exports.stringify = function (a) {
var v = a.slice(0, 3).join('.')
if (a[3] != null) {
v += '-' + a[3]
if (a[4] != null) {
v += '.' + a[4]
}
}
return v
}