Created
September 12, 2016 22:45
-
-
Save szanata/ce7d83e41aa00c1bf078e835721a4595 to your computer and use it in GitHub Desktop.
Camelize function for js
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
function camelize(val) { | |
return val.replace (/(?:^|[-_]|\s)(\w)/g, function (_, c, i) { | |
return i === 0 ? c.toLowerCase() : c.toUpperCase (); | |
}) | |
} | |
camelize('I like to develop') === 'iLikeToDevelop'; // separate words | |
camelize('i_like_to_develop') === 'iLikeToDevelop'; // underscore case | |
camelize('ILikeToDevelop') === 'iLikeToDevelop'; // pascal case | |
camelize('i_like ToDevelop') === 'iLikeToDevelop'; // mixed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment