UNPKG

@bussin/utilities

Version:

Helpful utilities, models, types, errors, and more.

15 lines 479 B
import { getRandomValues } from 'node:crypto'; export function generateUuid() { const bytes = new Uint8Array(16); getRandomValues(bytes); bytes[6] = (bytes[6] & 0x0f) | 0x40; bytes[8] = (bytes[8] & 0x3f) | 0x80; const uuid = [...bytes] .map((b, i) => { const hex = b.toString(16).padStart(2, '0'); return [4, 6, 8, 10].includes(i) ? `-${hex}` : hex; }) .join(''); return uuid; } //# sourceMappingURL=generateUuid.js.map