export class CodeGeneratorService { static generateCode(input_string: string) { if (!input_string) { throw new Error('Input string cannot be empty'); } // Step 1: Trim, to lowercase let code = input_string.trim().toLowerCase(); // Step 2: Replace all whitespace with underscores code = code.replace(/\s+/g, '_'); // Step 3: Remove all non-alphanumeric and non-underscore characters const sanitizedCode = code.replace(/[^a-z0-9_]/g, ''); if (!sanitizedCode) { throw new Error('Invalid input string, cannot generate code'); } return sanitizedCode; } }