Last active
August 29, 2015 14:08
-
-
Save chrisma/d052756be4ac383d0793 to your computer and use it in GitHub Desktop.
Javascript String helpers
This file contains hidden or 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.charAt(0).toUpperCase() + this.slice(1); | |
} | |
String.prototype.title = function(force) { | |
//'examPLE'.title(); -> 'ExamPLE' | |
//'examPLE'.title(true); -> 'Example' | |
return (force ? this.toLowerCase() : this).replace(/(?:^|\s)\S/g, function(s) { return s.toUpperCase(); }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment