aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-16 11:33:22 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit6702a1b2ccd666285dee9c72b5bace641d2fce8b (patch)
tree78b7125d664b6f6b6c993c4e8483e1bdd24a0a30 /shared/core-utils
parent503c6f440abc8f5924c38c4bd63591cb6cefacec (diff)
downloadPeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.tar.gz
PeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.tar.zst
PeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.zip
Add ability to search available plugins
Diffstat (limited to 'shared/core-utils')
-rw-r--r--shared/core-utils/miscs/miscs.ts20
1 files changed, 19 insertions, 1 deletions
diff --git a/shared/core-utils/miscs/miscs.ts b/shared/core-utils/miscs/miscs.ts
index c668e44c1..a3921b568 100644
--- a/shared/core-utils/miscs/miscs.ts
+++ b/shared/core-utils/miscs/miscs.ts
@@ -2,6 +2,24 @@ function randomInt (low: number, high: number) {
2 return Math.floor(Math.random() * (high - low) + low) 2 return Math.floor(Math.random() * (high - low) + low)
3} 3}
4 4
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
5export { 22export {
6 randomInt 23 randomInt,
24 compareSemVer
7} 25}