/** Converts a camelCase string to kebab-case. */ export function camelToKebab(string: string) { return ( string // Insert dash between a group of uppercase letters and an uppercase letter followed by lowercase (`HTTPSEncryptionMethod200Success` => `HTTPS-EncryptionMethod200Success`) .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2') // Insert dash between a lowercase letter and an uppercase letter (`HTTPS-EncryptionMethod200Success` => `HTTPS-Encryption-Method200Success`) .replace(/([a-z])([A-Z])/g, '$1-$2') // Insert dash between a letter and a digit (`HTTPS-Encryption-Method200Success` => `HTTPS-Encryption-Method-200Success`) .replace(/([A-Za-z])(\d)/g, '$1-$2') // Insert dash between a digit and a letter (`HTTPS-Encryption-Method-200Success` => `HTTPS-Encryption-Method-200-Success`) .replace(/(\d)([A-Za-z])/g, '$1-$2') // Convert to lowercase (`HTTPS-Encryption-Method-200-Success` => `https-encryption-method-200-success`) .toLowerCase() ) }