Created
November 20, 2012 07:42
-
-
Save taketin/4116615 to your computer and use it in GitHub Desktop.
capitalize method
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.capitalize = function() { | |
return this.toString().toLowerCase().replace(/\b[a-z]/g, function(letter) { | |
return letter.toUpperCase(); | |
}) | |
} |
- usage
str = 'hoge'
str.capitalize() // 'Hoge'
str = 'hoge fuga piyo'
str.capitalize() // 'Hoge Fuga Piyo'
str = 'hoge-fuga-piyo'
str.capitalize() // 'Hoge-Fuga-Piyo'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CoffeeScript