Created
February 1, 2013 00:19
-
-
Save qfox/4688012 to your computer and use it in GitHub Desktop.
Variable naming style converters via camelCase one
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() { | |
return this.substr(0, 1).toLowerCase() + this.substr(1).replace(/[\-_][a-z]/g, function($0){return $0.toUpperCase().replace(/[\_\-]/,'');}); | |
}; | |
String.prototype.toPascalCase = function() { | |
return this.substr(0, 1).toUpperCase() + this.substr(1).toCamelCase(); | |
}; | |
String.prototype.toUnderscore = function() { | |
return this.toCamelCase().replace(/[A-Z]/g, function($0){return "_"+$0.toLowerCase();}).replace(/^_/,''); | |
}; | |
String.prototype.toDash = function() { | |
return this.toCamelCase().replace(/[A-Z]/g, function($0){return "-"+$0.toLowerCase();}).replace(/^\-/,''); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment