MCPcopy Index your code
hub / github.com/ulid/javascript / ulidToUUID

Function ulidToUUID

source/uuid.ts:12–32  ·  view source on GitHub ↗
(ulid: ULID)

Source from the content-addressed store, hash-verified

10 * @returns A UUID string
11 */
12export function ulidToUUID(ulid: ULID): UUID {
13 const isValid = ULID_REGEX.test(ulid);
14 if (!isValid) {
15 throw new ULIDError(ULIDErrorCode.ULIDInvalid, `Invalid ULID: ${ulid}`);
16 }
17 const uint8Array = crockfordDecode(ulid);
18 let uuid = Array.from(uint8Array)
19 .map(byte => byte.toString(16).padStart(2, "0"))
20 .join("");
21 uuid =
22 uuid.substring(0, 8) +
23 "-" +
24 uuid.substring(8, 12) +
25 "-" +
26 uuid.substring(12, 16) +
27 "-" +
28 uuid.substring(16, 20) +
29 "-" +
30 uuid.substring(20);
31 return uuid.toUpperCase() as UUID;
32}
33
34/**
35 * Convert a UUID to a ULID

Callers 1

uuid.spec.tsFile · 0.85

Calls 1

crockfordDecodeFunction · 0.85

Tested by

no test coverage detected