/** * utils.js — Shared Utility Functions * * XSS defense and common helpers. */ /** * Escape HTML special characters to prevent XSS when using innerHTML. * @param {*} str - Value to escape (null/undefined → empty string) * @returns {string} HTML-safe string */ export function escapeHtml(str) { if (str == null) return ''; return String(str) .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); }