/** * Generate a unique deck ID in the format: xxxx-xxxx-xxxx (12 characters total) * Uses lowercase alphanumeric characters (a-z, 0-9) * * @returns A unique deck ID string * * @example * const deckId = generateDeckId(); * // Returns something like: "a3b2-c5d9-e7f1" */ export function generateDeckId(): string { const chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; const segments = [4, 4, 4]; return segments .map(len => Array.from({ length: len }, () => chars[Math.floor(Math.random() * chars.length)] ).join('') ) .join('-'); } /** * Validate if a string matches the deck ID format * * @param deckId - The deck ID string to validate * @returns True if the deck ID matches the expected format * * @example * isValidDeckId("a3b2-c5d9-e7f1"); // true * isValidDeckId("invalid"); // false */ export function isValidDeckId(deckId: string): boolean { const pattern = /^[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/; return pattern.test(deckId); }