PeerTube/shared/core-utils/common/version.ts

21 lines
515 B
TypeScript
Raw Normal View History

// Thanks https://stackoverflow.com/a/16187766
function compareSemVer (a: string, b: string) {
const regExStrip0 = /(\.0+)+$/
const segmentsA = a.replace(regExStrip0, '').split('.')
const segmentsB = b.replace(regExStrip0, '').split('.')
const l = Math.min(segmentsA.length, segmentsB.length)
for (let i = 0; i < l; i++) {
2020-01-31 09:56:52 -06:00
const diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10)
if (diff) return diff
}
return segmentsA.length - segmentsB.length
}
2019-04-24 08:10:37 -05:00
export {
compareSemVer
2019-04-24 08:10:37 -05:00
}