Skip to content

Instantly share code, notes, and snippets.

@frg
Created January 15, 2016 10:23
Show Gist options
  • Save frg/3fb713eff81b10e930c1 to your computer and use it in GitHub Desktop.
Save frg/3fb713eff81b10e930c1 to your computer and use it in GitHub Desktop.
JS - To Camel Case
String.prototype.toCamelCase = function() {
return this.replace(/(?:[^a-zA-Z\d\s\w:]|[A-Z]|\b\w|\s+)/g, function(match, index) {
if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces
return index == 0 ? match.toLowerCase() : match.toUpperCase();
}).replace(/[^a-zA-Z\d\s:]/g, '');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment