const snakeToCamelCase = (text) => { if (!(typeof text === "string" || text instanceof String)) { console.error(`string expected, ${typeof text} provided`) return text } text .toLowerCase() .replace(/([-_][a-z])/g, group => group .toUpperCase() .replace("-", "") .replace("_", "") ) } snakeToCamelCase("snake_case_to_camel_case") // snakeCaseToCamelCase
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter