UNPKG

@bussin/utilities

Version:

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

18 lines (17 loc) 564 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateUuid = generateUuid; const node_crypto_1 = require("node:crypto"); function generateUuid() { const bytes = new Uint8Array(16); (0, node_crypto_1.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; }