Last active
January 3, 2016 15:58
-
-
Save tigerclaw-az/8486035 to your computer and use it in GitHub Desktop.
Additional functions applied to the JavaScript String.prototype
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.capitalizeFirstLetter = function capitalizeFirstLetter() { | |
return this[0].toUpperCase() + this.slice(1); | |
}; | |
String.prototype.capitalizeAllWords = function capitalizeAllWords() { | |
return this.replace(/(^| )\w/g, function(match) { | |
return match.toUpperCase(); | |
}); | |
}; | |
String.prototype.partialMatch = function stringPartialMatch (compare) { | |
return this.match(new RegExp('(' + compare + '\\S*)', 'g')); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment