const ESCAPE_MAP = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' } const ESCAPE_RE = /[&<>"']/g /** * Escape HTML special characters to prevent XSS in email templates. * Returns empty string for null/undefined input. */ export function escapeHtml(str) { if (str == null) return '' return String(str).replace(ESCAPE_RE, (ch) => ESCAPE_MAP[ch]) }