]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/core-utils/miscs/miscs.ts
Try to reduce CSS size
[github/Chocobozzz/PeerTube.git] / shared / core-utils / miscs / miscs.ts
CommitLineData
34caef7f 1// high excluded
7c3b7976
C
2function randomInt (low: number, high: number) {
3 return Math.floor(Math.random() * (high - low) + low)
4}
5
6702a1b2
C
6// Thanks https://stackoverflow.com/a/16187766
7function compareSemVer (a: string, b: string) {
8 const regExStrip0 = /(\.0+)+$/
9 const segmentsA = a.replace(regExStrip0, '').split('.')
10 const segmentsB = b.replace(regExStrip0, '').split('.')
11
12 const l = Math.min(segmentsA.length, segmentsB.length)
13
14 for (let i = 0; i < l; i++) {
a1587156 15 const diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10)
6702a1b2
C
16
17 if (diff) return diff
18 }
19
20 return segmentsA.length - segmentsB.length
21}
22
b4055e1c
C
23function isPromise (value: any) {
24 return value && typeof value.then === 'function'
25}
26
27function isCatchable (value: any) {
28 return value && typeof value.catch === 'function'
29}
30
7c3b7976 31export {
6702a1b2 32 randomInt,
b4055e1c
C
33 compareSemVer,
34 isPromise,
35 isCatchable
7c3b7976 36}