manifold/og-image/api/_lib/sanitizer.ts
2022-01-06 17:28:20 -08:00

13 lines
264 B
TypeScript

const entityMap: { [key: string]: string } = {
"&": "&",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#39;",
"/": "&#x2F;",
};
export function sanitizeHtml(html: string) {
return String(html).replace(/[&<>"'\/]/g, (key) => entityMap[key]);
}