diff options
author | Chocobozzz <me@florianbigard.com> | 2023-01-19 13:53:24 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-01-19 13:54:53 +0100 |
commit | 6e06694fd6acab185432bccf57bd5c9c3b68f218 (patch) | |
tree | 57fb4069ff366f0b57c138acf9e3d91397d2bc50 /shared | |
parent | f008e9f3f34ed1724afd5e071c39ed931741acbc (diff) | |
download | PeerTube-6e06694fd6acab185432bccf57bd5c9c3b68f218.tar.gz PeerTube-6e06694fd6acab185432bccf57bd5c9c3b68f218.tar.zst PeerTube-6e06694fd6acab185432bccf57bd5c9c3b68f218.zip |
Fix semver comparison
Diffstat (limited to 'shared')
-rw-r--r-- | shared/core-utils/common/version.ts | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/shared/core-utils/common/version.ts b/shared/core-utils/common/version.ts index 8a64f8c4d..305287233 100644 --- a/shared/core-utils/common/version.ts +++ b/shared/core-utils/common/version.ts | |||
@@ -1,18 +1,9 @@ | |||
1 | // Thanks https://stackoverflow.com/a/16187766 | 1 | // Thanks https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb |
2 | function compareSemVer (a: string, b: string) { | 2 | function compareSemVer (a: string, b: string) { |
3 | const regExStrip0 = /(\.0+)+$/ | 3 | if (a.startsWith(b + '-')) return -1 |
4 | const segmentsA = a.replace(regExStrip0, '').split('.') | 4 | if (b.startsWith(a + '-')) return 1 |
5 | const segmentsB = b.replace(regExStrip0, '').split('.') | ||
6 | 5 | ||
7 | const l = Math.min(segmentsA.length, segmentsB.length) | 6 | return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'case', caseFirst: 'upper' }) |
8 | |||
9 | for (let i = 0; i < l; i++) { | ||
10 | const diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10) | ||
11 | |||
12 | if (diff) return diff | ||
13 | } | ||
14 | |||
15 | return segmentsA.length - segmentsB.length | ||
16 | } | 7 | } |
17 | 8 | ||
18 | export { | 9 | export { |