Created
October 17, 2021 19:00
-
-
Save lior-amsalem/be7d1dda62a761291c368634035e0938 to your computer and use it in GitHub Desktop.
convert string to camelCase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Examples | |
"the-stealth-warrior" gets converted to "theStealthWarrior" | |
"The_Stealth_Warrior" gets converted to "TheStealthWarrior" | |
**/ | |
function toCamelCase(str){ | |
return str.replace(/[-_][a-zA-Z]/g, (i) => i.replace(/[-_]/g,'').toUpperCase()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment