/** * Generates a random unique ID (UUID v4 style) */ export function generateId(): string { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { const r = (Math.random() * 16) | 0; const v = c === 'x' ? r : (r & 0x3) | 0x8; return v.toString(16); }); } /** * Deep-clone a plain object */ export function deepClone(obj: T): T { return JSON.parse(JSON.stringify(obj)); } /** * Safely get a nested value by dot-path e.g. "user.email" */ export function getNestedValue(obj: Record, path: string): any { return path.split('.').reduce((acc, key) => acc?.[key], obj); } /** * Set a nested value by dot-path e.g. "user.email" */ export function setNestedValue( obj: Record, path: string, value: any ): void { const keys = path.split('.'); const last = keys.pop()!; const target = keys.reduce((acc, key) => { if (!acc[key]) acc[key] = {}; return acc[key]; }, obj); target[last] = value; }