Skip to content

Instantly share code, notes, and snippets.

@uurtech
Last active December 31, 2019 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uurtech/ccead22280344970093123e2aa0902a5 to your computer and use it in GitHub Desktop.
Save uurtech/ccead22280344970093123e2aa0902a5 to your computer and use it in GitHub Desktop.
Typescript strip tags and full trim string prototype
declare global {
interface String {
fullTrim();
strip();
cleanQuotas();
cleanCommas();
floatReplacer();
cleanHtmlChars();
}
interface Object {
validate();
}
}
String.prototype.fullTrim=function(){
return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))|\(|\)/g,'').replace(/\s+/g,'');
};
String.prototype.cleanHtmlChars=function(){
return this.replace(/&(.*?);/g,'');
}
String.prototype.strip=function(){
return this.replace(/<[^>]*>?/gm, '');
}
String.prototype.cleanQuotas=function(){
return this.replace(/\"/g,'');
}
String.prototype.cleanCommas=function(){
return this.replace(/,/g,'');
}
String.prototype.floatReplacer=function(){
return this.replace(/,/g,'.');
}
Object.prototype.validate=function(){
if(typeof this === "object" && this !== null){
return true;
}
return false;
}
export {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment