marko
Version:
UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.
21 lines (17 loc) • 403 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.bt_ = escape;