MCPcopy
hub / github.com/ulid/javascript / uuidToULID

Function uuidToULID

source/uuid.ts:39–50  ·  view source on GitHub ↗
(uuid: string)

Source from the content-addressed store, hash-verified

37 * @returns A ULID string
38 */
39export function uuidToULID(uuid: string): ULID {
40 const isValid = UUID_REGEX.test(uuid);
41 if (!isValid) {
42 throw new ULIDError(ULIDErrorCode.UUIDInvalid, `Invalid UUID: ${uuid}`);
43 }
44 const bytes = uuid.replace(/-/g, "").match(/.{1,2}/g);
45 if (!bytes) {
46 throw new ULIDError(ULIDErrorCode.Unexpected, `Failed parsing UUID bytes: ${uuid}`);
47 }
48 const uint8Array = new Uint8Array(bytes.map(byte => parseInt(byte, 16)));
49 return crockfordEncode(uint8Array);
50}

Callers 1

uuid.spec.tsFile · 0.85

Calls 1

crockfordEncodeFunction · 0.85

Tested by

no test coverage detected