Created
July 21, 2011 09:31
-
-
Save charlieschwabacher/1096850 to your computer and use it in GitHub Desktop.
Javascript string presentation methods with underscore.js (upper, lower, capitalize, title)
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.upper = function() { | |
return _.reduce(this.split(""), function(memo, chr) { return memo + chr.toUpperCase() }, "") | |
} | |
String.prototype.lower = function() { | |
return _.reduce(this.split(""), function(memo, chr) { return memo + chr.toLowerCase() }, "") | |
} | |
String.prototype.capitalize = function() { | |
return this.charAt(0).toUpperCase() + this.slice(1); | |
} | |
String.prototype.title = function() { | |
return _.reduce(this.lower().split(" "), function(memo, word) { return memo + " " + word.capitalize() }, "").slice(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment