unescape_html.js 445 B

12345678910111213141516171819202122
  1. 'use strict';
  2. const htmlEntityMap = {
  3. '&': '&',
  4. '&lt;': '<',
  5. '&gt;': '>',
  6. '&quot;': '"',
  7. '&#39;': '\'',
  8. '&#96;': '`',
  9. '&#x2F;': '/',
  10. '&#x3D;': '='
  11. };
  12. const regexHtml = new RegExp(Object.keys(htmlEntityMap).join('|'), 'g');
  13. const unescapeHTML = str => {
  14. if (typeof str !== 'string') throw new TypeError('str must be a string!');
  15. return str.replace(regexHtml, a => htmlEntityMap[a]);
  16. };
  17. module.exports = unescapeHTML;