escapeHtml.js 410 B

123456789101112131415161718
  1. var toString = require('../lang/toString');
  2. /**
  3. * Escapes a string for insertion into HTML.
  4. */
  5. function escapeHtml(str){
  6. str = toString(str)
  7. .replace(/&/g, '&')
  8. .replace(/</g, '&lt;')
  9. .replace(/>/g, '&gt;')
  10. .replace(/'/g, '&#39;')
  11. .replace(/"/g, '&quot;');
  12. return str;
  13. }
  14. module.exports = escapeHtml;