aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/uuid.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/uuid.ts')
-rw-r--r--shared/extra-utils/uuid.ts32
1 files changed, 32 insertions, 0 deletions
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 @@
1import short, { uuid } from 'short-uuid'
2
3const translator = short()
4
5function buildUUID () {
6 return uuid()
7}
8
9function uuidToShort (uuid: string) {
10 if (!uuid) return uuid
11
12 return translator.fromUUID(uuid)
13}
14
15function shortToUUID (shortUUID: string) {
16 if (!shortUUID) return shortUUID
17
18 return translator.toUUID(shortUUID)
19}
20
21function isShortUUID (value: string) {
22 if (!value) return false
23
24 return value.length === translator.maxLength
25}
26
27export {
28 buildUUID,
29 uuidToShort,
30 shortToUUID,
31 isShortUUID
32}