@tanstack/db
Version:
A reactive client store for building super fast apps on sync
17 lines (16 loc) • 1 kB
JavaScript
import { codedMessage, devBuild } from "../error-message.js";
function safeRandomUUID() {
const c = typeof globalThis !== `undefined` ? globalThis.crypto : void 0;
if (c && typeof c.randomUUID === `function`) return c.randomUUID();
if (c && typeof c.getRandomValues === `function`) {
const bytes = c.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
bytes[6] = bytes[6] & 15 | 64;
bytes[8] = bytes[8] & 63 | 128;
const hex = [];
for (let i = 0; i < 16; i++) hex.push(bytes[i].toString(16).padStart(2, `0`));
return hex.slice(0, 4).join(``) + `-` + hex.slice(4, 6).join(``) + `-` + hex.slice(6, 8).join(``) + `-` + hex.slice(8, 10).join(``) + `-` + hex.slice(10, 16).join(``);
}
throw new Error(/* @__PURE__ */ devBuild() && process.env.NODE_ENV !== `production` ? `No secure random number generator available: neither crypto.randomUUID nor crypto.getRandomValues is defined in this environment.` : codedMessage(171));
}
export { safeRandomUUID };
//# sourceMappingURL=uuid.js.map