thread-master/apps/web/src/lib/id.ts

7 lines
268 B
TypeScript
Raw Normal View History

2026-07-10 05:10:31 +00:00
export function newId(prefix = "id"): string {
if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
return `${prefix}_${crypto.randomUUID().slice(0, 8)}`;
}
return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
}