Files
snapcad-studio/apps/web/src/lib/localIds.ts
T

14 lines
461 B
TypeScript
Raw Normal View History

2026-06-14 22:05:58 +03:00
let fallbackIdCounter = 0;
export function createLocalId(prefix: string) {
const uuid = globalThis.crypto?.randomUUID?.();
if (uuid) {
return `${prefix}-${uuid}`;
}
fallbackIdCounter = (fallbackIdCounter + 1) % Number.MAX_SAFE_INTEGER;
const timestamp = Date.now().toString(36);
const counter = fallbackIdCounter.toString(36);
const random = Math.random().toString(36).slice(2, 10);
return `${prefix}-${timestamp}-${counter}-${random}`;
}