@tanstack/db
Version:
A reactive client store for building super fast apps on sync
24 lines (23 loc) • 883 B
JavaScript
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(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(
`No secure random number generator available: neither crypto.randomUUID nor crypto.getRandomValues is defined in this environment.`
);
}
export {
safeRandomUUID
};
//# sourceMappingURL=uuid.js.map