rvx
Version:
A signal based rendering library
43 lines • 1.12 kB
JavaScript
const HTML_ESCAPE_REGEX = /["'<>&]/;
export function htmlEscapeAppendTo(html, data) {
const firstMatch = HTML_ESCAPE_REGEX.exec(data);
if (firstMatch === null) {
return html + data;
}
let last = 0;
let index = firstMatch.index;
let escape;
chars: while (index < data.length) {
switch (data.charCodeAt(index)) {
case 34:
escape = """;
break;
case 38:
escape = "&";
break;
case 39:
escape = "'";
break;
case 60:
escape = "<";
break;
case 62:
escape = ">";
break;
default:
index++;
continue chars;
}
if (index !== last) {
html += data.slice(last, index);
}
html += escape;
index++;
last = index;
}
if (index !== last) {
html += data.slice(last, index);
}
return html;
}
//# sourceMappingURL=html-escape.js.map