AitorAlejandro
1/2/2018 - 12:57 PM

Escapes a string for use in HTML

Escapes a string for use in HTML

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