Created
April 20, 2013 03:11
-
-
Save johnsmith17th/5424570 to your computer and use it in GitHub Desktop.
To convert string to camel case in javascript.
This file contains 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
function toCamelCase(str) { | |
return str.toLowerCase().replace(/(?:(^.)|(\s+.))/g, function(match) { | |
return match.charAt(match.length-1).toUpperCase(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Small changes to the above to allow for kebab and snake case input, as well as proper camelCase rather than PascalCase as @mcarlucci pointed out.
Fork: https://gist.github.com/timhobbs/23c891bfea312cf43f31395d2d6660b1
EDIT: I tried the gist from @assembledadam above but it did not seem to work for me.