Files
fangke/sdk/src/util.ts
T

9 lines
311 B
TypeScript

export function uuid(): string {
const c = globalThis.crypto as Crypto | undefined;
if (c?.randomUUID) return c.randomUUID();
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
});
}