Files
30-seconds-of-code/test/escapeHTML/escapeHTML.js
2018-01-17 13:40:40 -05:00

13 lines
175 B
JavaScript

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