Hello
'; 29 | * const result = purgeXmltags(str); 30 | * console.log(result); 31 | * // Hello 32 | */ 33 | public purgeXmltags(str: string): string { 34 | str = str.replace(/['"]+/g, ''); 35 | str = this.xmlRemoveScript(str); 36 | return str.replace(/<[^>]*>/g, ''); 37 | } 38 | 39 | /** 40 | * Xmls remove coments 41 | * @param str 42 | * @returns remove coments 43 | */ 44 | public xmlRemoveComents(str: string): string { 45 | str = str.replace(/['"]+/g, ''); 46 | str = str.replace(/\[/g, ''); 47 | return str.replace(//g, ''); 48 | } 49 | 50 | /** 51 | * Xmls remove script 52 | * @param str 53 | * @returns remove script 54 | */ 55 | public xmlRemoveScript(str: string): string { 56 | str = str.replace(/['"]+/g, ''); 57 | return this.htmlRemoveScript(this.xmlRemoveComents(str)); 58 | } 59 | 60 | /** 61 | * Xmls remove cdata 62 | * @param str 63 | * @returns remove cdata 64 | */ 65 | public xmlRemoveCdata(str: string): string { 66 | str = str.replace(/['"]+/g, ''); 67 | return str.replace(//g, ''); 68 | } 69 | 70 | /** 71 | * Purges html 72 | * @param str 73 | * @returns string 74 | * 75 | * @example 76 | * ``` 77 | * const str = 'Hello
'; 78 | * const result = purgeHtml(str); 79 | * console.log(result); 80 | * // Hello 81 | */ 82 | public purgeHtml(str: string): string { 83 | str = str.replace(/['"]+/g, ''); 84 | str = this.xmlRemoveScript(str); 85 | str = this.xmlRemoveCdata(str); 86 | str = this.xmlRemoveComents(str); 87 | str = this.purgeXmltags(str); 88 | return this.htmlSanitize(str); 89 | } 90 | 91 | /** 92 | * Htmls sanitize 93 | * @param str 94 | * @returns sanitized string 95 | */ 96 | public htmlSanitize(str: string): string { 97 | return str 98 | .replace(/&/g, '&') 99 | .replace(//g, '>') 101 | .replace(/"/g, '"') 102 | .replace(/'/g, '''); 103 | } 104 | 105 | /** 106 | * Htmls remove coments 107 | * @param str 108 | * @returns remove coments 109 | */ 110 | public htmlRemoveComents(str: string): string { 111 | str = str.replace(/['"]+/g, ''); 112 | return str.replace(//g, ''); 113 | } 114 | 115 | /** 116 | * Htmls remove script 117 | * @param str 118 | * @returns remove script 119 | */ 120 | public htmlRemoveScript(str: string): string { 121 | str = str.replace(/['"]+/g, ''); 122 | str = str.replace(/\[/g, ''); 123 | str = str.replace(/