diff options
Diffstat (limited to 'shared/core-utils/common')
-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 { |