refactor: remove duplicate escape functions; improve escapeHtml function

This commit is contained in:
2026-04-24 08:52:14 -04:00
parent 9064aecedb
commit 38dd017dcd
3 changed files with 18 additions and 12 deletions
+12
View File
@@ -0,0 +1,12 @@
const htmlEscapeMap: Record<string, string> = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
'`': '&#96;'
};
export function escapeHtml(value: string): string {
return value.replace(/[&<>"'`]/g, (char) => htmlEscapeMap[char]);
}