Files
30-seconds-of-code/test/escapeHTML/escapeHTML.js
2018-01-09 06:09:49 -05:00

12 lines
144 B
JavaScript

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