Skip to content

Instantly share code, notes, and snippets.

@loickreitmann
Created April 14, 2011 22:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loickreitmann/920765 to your computer and use it in GitHub Desktop.
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".
/**
* 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