marko
Version:
UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.
22 lines (17 loc) • 425 B
JavaScript
;
const unsafeCharsRegExp = /[<&]/g;
const replaceMatch = (c) => (c === "&" ? "&" : "<");
const escape = (str) =>
unsafeCharsRegExp.test(str)
? str.replace(unsafeCharsRegExp, replaceMatch)
: str;
module.exports.x = function (value) {
if (value == null) {
return "";
}
if (value.toHTML) {
return value.toHTML();
}
return escape(value + "");
};
exports.___escapeXML = escape;