All files utils.ts

53.84% Statements 7/13
33.33% Branches 2/6
33.33% Functions 1/3
60% Lines 6/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 371x                   1x           1x 8x                       1x 1x            
const HTML_CHARS: Record<string, string> = {
	"&":"&amp;",
	"<":"&lt;",
	">":"&gt;",
	'"':"&quot;",
	"'":"&#039;",
	"{":"&lcub;",
	"}":"&rcub;"
}
 
const ESC_REG = /[&<>"'\{\}]/g;
 
/**
 * The escape method should be used sparingly. because for example it can over escape a string if already escaped one. that being said this function should be unecessary once addon full supports the spec.
 * @param text 
 */
export const escape = (text:string)=>{
	return text ? text.replace(ESC_REG, match=>HTML_CHARS[match]):'';
}
 
/**
 * Its just more convenient if this is attached to the string prototype.
 */
declare global {
	interface String {
		wrap(a: string, b:string):string
	}
}
 
if (!String.prototype.wrap) {
	String.prototype.wrap = function(a: string='', b: string=''){
		Iif(!this.toString().trim()) return '';
		a = escape(a);
		b = escape(b);
		return `${a}${this}${b}`; //this should already be escaped
	}
}