From 0628157fe9662fdb2b6fa658b8b53fe684c013ce Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 29 Dec 2021 14:44:58 +0100 Subject: Move uuid stuff in extra utils Since it requires an external dependency --- shared/extra-utils/index.ts | 1 + shared/extra-utils/uuid.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 shared/extra-utils/uuid.ts (limited to 'shared/extra-utils') diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 373d27cb4..e2e161a7b 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -1,3 +1,4 @@ export * from './crypto' export * from './ffprobe' export * from './file' +export * from './uuid' diff --git a/shared/extra-utils/uuid.ts b/shared/extra-utils/uuid.ts new file mode 100644 index 000000000..f3c80e046 --- /dev/null +++ b/shared/extra-utils/uuid.ts @@ -0,0 +1,32 @@ +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 +} -- cgit v1.2.3