Files
30-seconds-of-code/test/escapeHTML/escapeHTML.js

12 lines
157 B
JavaScript

module.exports = escapeHTML = str =>
str.replace(
/[&<>'"]/g,
tag =>
({
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
"'": '&#39;',
'"': '&quot;'
}[tag] || tag)
);