Created
March 5, 2013 16:04
-
-
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()
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
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