Coves frontend - a photon fork
at main 15 lines 626 B view raw
1/** 2 * Generates a unique ID for form elements (labels, inputs, etc.). 3 * Uses crypto.randomUUID() for collision-resistant IDs. 4 */ 5export const generateID = (): string => { 6 // crypto.randomUUID() is available in all modern browsers and Node.js 19+ 7 // It generates a RFC 4122 compliant UUID v4 8 if (typeof crypto !== 'undefined' && crypto.randomUUID) { 9 return crypto.randomUUID() 10 } 11 12 // Fallback for environments without crypto.randomUUID (older Node.js) 13 // Uses timestamp + high-entropy random string to minimize collision risk 14 return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 11)}` 15}