14 lines
275 B
TypeScript
14 lines
275 B
TypeScript
// Small shared helpers.
|
|
|
|
const ESCAPE_MAP: Record<string, string> = {
|
|
'&': '&',
|
|
'<': '<',
|
|
'>': '>',
|
|
'"': '"',
|
|
"'": ''',
|
|
};
|
|
|
|
export function escapeHtml(str: string): string {
|
|
return String(str).replace(/[&<>"']/g, (c) => ESCAPE_MAP[c] ?? c);
|
|
}
|