]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import short, { uuid } from 'short-uuid' |
d4a8e7a6 C |
2 | |
3 | const translator = short() | |
4 | ||
5 | function buildUUID () { | |
41fb13c3 | 6 | return uuid() |
d4a8e7a6 C |
7 | } |
8 | ||
9 | function uuidToShort (uuid: string) { | |
10 | if (!uuid) return uuid | |
11 | ||
12 | return translator.fromUUID(uuid) | |
13 | } | |
14 | ||
15 | function shortToUUID (shortUUID: string) { | |
16 | if (!shortUUID) return shortUUID | |
17 | ||
18 | return translator.toUUID(shortUUID) | |
19 | } | |
20 | ||
21 | function isShortUUID (value: string) { | |
22 | if (!value) return false | |
23 | ||
24 | return value.length === translator.maxLength | |
25 | } | |
26 | ||
27 | export { | |
28 | buildUUID, | |
29 | uuidToShort, | |
30 | shortToUUID, | |
31 | isShortUUID | |
32 | } |