mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-03 23:53:46 +00:00
13 lines
359 B
TypeScript
13 lines
359 B
TypeScript
const fallback = () => Math.random().toString(16).slice(2)
|
|
|
|
export function uuid() {
|
|
const c = globalThis.crypto
|
|
if (!c || typeof c.randomUUID !== "function") return fallback()
|
|
if (typeof globalThis.isSecureContext === "boolean" && !globalThis.isSecureContext) return fallback()
|
|
try {
|
|
return c.randomUUID()
|
|
} catch {
|
|
return fallback()
|
|
}
|
|
}
|