camelCase to kebab-case
I have a one-liner similar to Marc’s but with a simpler Regular Expression and ~20% faster according my benchmark (Chrome 89). const kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? “-” : “”) + $.toLowerCase()) const words = [‘StackOverflow’, ‘camelCase’, ‘alllowercase’, ‘ALLCAPITALLETTERS’, ‘CustomXMLParser’, ‘APIFinder’, ‘JSONResponseData’, ‘Person20Address’, ‘UserAPI20Endpoint’]; console.log(words.map(kebabize)); [A-Z]+(?![a-z]) matches any consecutive capital … Read more