]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/core-utils/miscs/miscs.ts
Add ability to disable plugins/themes from CLI
[github/Chocobozzz/PeerTube.git] / shared / core-utils / miscs / miscs.ts
CommitLineData
7c3b7976
C
1function randomInt (low: number, high: number) {
2 return Math.floor(Math.random() * (high - low) + low)
3}
4
6702a1b2
C
5// Thanks https://stackoverflow.com/a/16187766
6function compareSemVer (a: string, b: string) {
7 const regExStrip0 = /(\.0+)+$/
8 const segmentsA = a.replace(regExStrip0, '').split('.')
9 const segmentsB = b.replace(regExStrip0, '').split('.')
10
11 const l = Math.min(segmentsA.length, segmentsB.length)
12
13 for (let i = 0; i < l; i++) {
14 const diff = parseInt(segmentsA[ i ], 10) - parseInt(segmentsB[ i ], 10)
15
16 if (diff) return diff
17 }
18
19 return segmentsA.length - segmentsB.length
20}
21
7c3b7976 22export {
6702a1b2
C
23 randomInt,
24 compareSemVer
7c3b7976 25}