21 lines
528 B
JavaScript
21 lines
528 B
JavaScript
const sanitize = require("sanitize-html");
|
|
|
|
exports.sanitizeHtml = (html = "") => {
|
|
return sanitize(html, {
|
|
allowedTags: sanitize.defaults.allowedTags.concat(["img"]),
|
|
allowedAttributes: {
|
|
"*": ["style", "class"],
|
|
img: ["src", "alt"]
|
|
},
|
|
disallowedTagsMode: "discard"
|
|
});
|
|
};
|
|
|
|
exports.sanitizeForLog = (value) => {
|
|
if (typeof value !== "string") return value;
|
|
return value
|
|
.replace(/[\r\n]+/g, " ")
|
|
.replace(/\t+/g, " ")
|
|
.replace(/[^\x20-\x7E]+/g, " ");
|
|
};
|