/ Published in: JavaScript
"example_one".toCamelCase(); // => exampleOne "Example-Two".toCamelCase(); // => ExampleTwo "example-Three".toLowerCase().toCamelCase(); // => exampleTwo
// execption: BestPCCode => BestPccode
Expand |
Embed | Plain Text
String.prototype.toCamelCase = function() { return this.toString() .replace(/([A-Z]+)/g, function(m,l){ return l.substr(0,1).toUpperCase() + l.toLowerCase().substr(1,l.length); }) .replace(/[\-_\s](.)/g, function(m, l){ return l.toUpperCase(); }); };
You need to login to post a comment.
