Skip to content

Instantly share code, notes, and snippets.

@khacanh
Last active December 18, 2015 21:29
Show Gist options
  • Save khacanh/5847921 to your computer and use it in GitHub Desktop.
Save khacanh/5847921 to your computer and use it in GitHub Desktop.
Some js extensions
String.prototype.capitalize = function() {
return this.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
String.prototype.contains = function(subStr) {
return this.indexOf(subStr) !== -1;
};
String.prototype.containsWord = function(word) {
var expStr = Mustache.render(" {{word}} |^{{word}} | {{word}}$|^{{word}}$", {word: word});
return this.match(new RegExp(expStr, "i")) != null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment