escape-html.js 201 B

12345678910111213
  1. const map = {
  2. "&": "&",
  3. "<": "&lt;",
  4. ">": "&gt;",
  5. '"': "&quot;",
  6. "'": "&#039;"
  7. }
  8. export default function(text) {
  9. return text.replace(/[&<>"']/g, function(m) {
  10. return map[m]
  11. })
  12. }