2026-09-15 11:30:42 +08:00
|
|
|
export function uuid(): string {
|
2026-09-15 11:39:34 +08:00
|
|
|
const c = globalThis.crypto as Crypto | undefined;
|
|
|
|
|
if (c?.randomUUID) return c.randomUUID();
|
2026-09-15 11:30:42 +08:00
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|