Move uuid stuff in extra utils

Since it requires an external dependency
This commit is contained in:
Chocobozzz
2021-12-29 14:44:58 +01:00
parent fb3c9e2bf5
commit 0628157fe9
30 changed files with 44 additions and 28 deletions
+5
View File
@@ -10,6 +10,10 @@ function pick <O extends object, K extends keyof O> (object: O, keys: K[]): Pick
return result
}
function getKeys <O extends object, K extends keyof O> (object: O, keys: K[]): K[] {
return (Object.keys(object) as K[]).filter(k => keys.includes(k))
}
function sortObjectComparator (key: string, order: 'asc' | 'desc') {
return (a: any, b: any) => {
if (a[key] < b[key]) {
@@ -26,5 +30,6 @@ function sortObjectComparator (key: string, order: 'asc' | 'desc') {
export {
pick,
getKeys,
sortObjectComparator
}
+1 -1
View File
@@ -1,4 +1,4 @@
import { VideoResolution } from "@shared/models"
import { VideoResolution } from '@shared/models'
type BitPerPixel = { [ id in VideoResolution ]: number }
-1
View File
@@ -1,3 +1,2 @@
export * from './bitrate'
export * from './privacy'
export * from './uuid'
-32
View File
@@ -1,32 +0,0 @@
import short, { uuid } from 'short-uuid'
const translator = short()
function buildUUID () {
return uuid()
}
function uuidToShort (uuid: string) {
if (!uuid) return uuid
return translator.fromUUID(uuid)
}
function shortToUUID (shortUUID: string) {
if (!shortUUID) return shortUUID
return translator.toUUID(shortUUID)
}
function isShortUUID (value: string) {
if (!value) return false
return value.length === translator.maxLength
}
export {
buildUUID,
uuidToShort,
shortToUUID,
isShortUUID
}