this repo has no description
at main 12 lines 256 B view raw
1const HTML_CHARS_REGEX = /[&<>"']/g; 2const HTML_ENTITIES = { 3 '&': '&amp;', 4 '<': '&lt;', 5 '>': '&gt;', 6 '"': '&quot;', 7 "'": '&apos;', 8}; 9 10export default function escapeHTML(text) { 11 return text.replace(HTML_CHARS_REGEX, (c) => HTML_ENTITIES[c]); 12}