Skip to content

Instantly share code, notes, and snippets.

@tigerclaw-az
Last active January 3, 2016 15:58
Show Gist options
  • Save tigerclaw-az/8486035 to your computer and use it in GitHub Desktop.
Save tigerclaw-az/8486035 to your computer and use it in GitHub Desktop.
Additional functions applied to the JavaScript String.prototype
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