velt/text: HTML escaping
import { escapeHtml } from "velt/text". Escapes text for HTML element content and quoted
attribute values in one pass: &, <, >, " and ' become &, <, >,
" and '; everything else (including non-ASCII) is kept.
ts
import { escapeHtml } from "velt/text";
const name = `<b>"Tom" & 'Jerry'</b>`;
console.log(`<td title="${escapeHtml(name)}">${escapeHtml(name)}</td>`);
// <td title="<b>"Tom" & 'Jerry'</b>"><b>"Tom…</td>JSX escapes text and attribute values itself (velt/jsx); escapeHtml is for
HTML built as strings.