]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/core-utils/uuid.ts
chore(refactor): remove shared folder dependencies to the server
[github/Chocobozzz/PeerTube.git] / shared / core-utils / uuid.ts
diff --git a/shared/core-utils/uuid.ts b/shared/core-utils/uuid.ts
new file mode 100644 (file)
index 0000000..f3c80e0
--- /dev/null
@@ -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
+}