Created
April 14, 2011 22:51
-
-
Save loickreitmann/920765 to your computer and use it in GitHub Desktop.
Simple String method to convert a string to camel case (i.e, "This is my string!? Dashes - removed !@#$%^&*()(.+=;':[]}{<>|,./\"" converts to "thisIsMyStringDashesRemoved".
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
/** | |
* toCamelCase: converts string to camel case | |
*/ | |
String.prototype.toCameCase = function () { | |
return this.replace(/^\s+|\s+$/g, "") | |
.toLowerCase() | |
.replace(/(\s[a-z0-9])/g, function ($1) { | |
return $1.replace(/\s/, '').toUpperCase(); | |
}) | |
.replace(/\W/g, ''); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment