Skip to content

Instantly share code, notes, and snippets.

@osartun
Created March 5, 2013 16:04
Show Gist options
  • Save osartun/5091370 to your computer and use it in GitHub Desktop.
Save osartun/5091370 to your computer and use it in GitHub Desktop.
Formats a string and returns it in camel case. "Hello World" becomes "helloWorld". As this was just a quick idea, I attached this function to the String's prototype, and so giving a sh*t on best practices. But anyway. You can use it like this: "Hello World".toCamelCase()
String.prototype.toCamelCase = (function (regExp) {
return function () {
return this.toLowerCase().replace(regExp, function (m, a, b) {return a + b.toUpperCase();})
}
})(/(\w)[ \t\r\n\-](\w)/g);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment