apps/gateway/src/utils/uuid.ts
Metadata
- Purpose: Source artifact in the anchor-msp system.
- Domain:
applications - Language:
ts - Bytes: 460
- Lines: 20
- Content hash (short):
6cb0b04e - Source (start): apps/gateway/src/utils/uuid.ts:1
- Source (end): apps/gateway/src/utils/uuid.ts:20
Indexed Symbols
isUuid(line 5, function) - Implements is uuid for module behavior.ensureUuid(line 9, function) - Implements ensure uuid for module behavior.
Markdown Headings (if applicable)
No markdown headings detected.
Source Preview
import { randomUUID } from "node:crypto";
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
export function isUuid(value: string): boolean {
return uuidRegex.test(value);
}
export function ensureUuid(value: unknown, fallback?: string): string {
if (typeof value === "string" && isUuid(value)) {
return value;
}
if (fallback && isUuid(fallback)) {
return fallback;
}
return randomUUID();
}