escapeHTML.js 390 B

1234567891011121314151617
  1. var makeString = require('./helper/makeString');
  2. var escapeChars = require('./helper/escapeChars');
  3. var regexString = '[';
  4. for(var key in escapeChars) {
  5. regexString += key;
  6. }
  7. regexString += ']';
  8. var regex = new RegExp( regexString, 'g');
  9. module.exports = function escapeHTML(str) {
  10. return makeString(str).replace(regex, function(m) {
  11. return '&' + escapeChars[m] + ';';
  12. });
  13. };