-
-
Save ZoolWay/f1db0621a2f2875c56bc47224db2a112 to your computer and use it in GitHub Desktop.
String.camelize
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
// I thought I needed it, but I didn't need it anymore, | |
// but I already implemented it. So, here we go, if you | |
// ever would need a Javascript camelize implementation | |
// you can freely use this :-). | |
// - [email protected] Tue Feb 15 16:49:52 CET 2011 | |
jQuery.extend (String.prototype, { | |
camelize: function () { | |
return s.replace(/(?:^|[-_])(\w)/g, function (stripped, letter) { | |
return letter ? letter.toUpperCase () : ''; | |
}).replace(/(^\w)/, function(letter) { return letter.toLowerCase()}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This reviews correctly lowers the very first letter (otherwise we have PascalCase, not camelCase).