Files
30-seconds-of-code/test/escapeHTML/escapeHTML.js
2018-02-04 17:38:39 +02:00

13 lines
175 B
JavaScript

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