Code coverage report for master/unescapeHTML.js

Statements: 100% (12 / 12)      Branches: 100% (6 / 6)      Functions: 100% (2 / 2)      Lines: 100% (12 / 12)      Ignored: none     

All files » master/ » unescapeHTML.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 191 1   1 23 31   31 21 10 2 8 5   3        
var makeString = require('./helper/makeString');
var htmlEntities = require('./helper/htmlEntities');
 
module.exports = function unescapeHTML(str) {
  return makeString(str).replace(/\&([^;]+);/g, function(entity, entityCode) {
    var match;
 
    if (entityCode in htmlEntities) {
      return htmlEntities[entityCode];
    } else if (match = entityCode.match(/^#x([\da-fA-F]+)$/)) {
      return String.fromCharCode(parseInt(match[1], 16));
    } else if (match = entityCode.match(/^#(\d+)$/)) {
      return String.fromCharCode(~~match[1]);
    } else {
      return entity;
    }
  });
};