Skip to content

Instantly share code, notes, and snippets.

@hunterc

hunterc/stringUtil.js

Last active Aug 29, 2015
Embed
What would you like to do?
JS String startsWith, endsWith methods
var stringUtil = (function(global)) {
// prototype modifiers
if (typeof String.prototype.startsWith !== 'function') {
String.prototype.startsWith = function(str) {
return this.slice(0, str.length) === str;
};
}
if (typeof String.prototype.endsWith !== 'function') {
String.prototype.endsWith = function(str) {
return this.slice(-str.length) === str;
};
}
if (typeof String.prototype.stripTags !== 'function') {
String.prototype.stripTags = function() {
return this.replace(/(<([^>]+)>)/ig,"");
}
}
/*
add new functions here
ex:
var example = function(str) {
// do something to str....
return str;
};
*/
/*
expose new functions: key value pairing
key => name used to call function in stringUtil
value => private function declared inside stringUtil
ex:
return {
ex: example
};
*/
return {
};
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.