To avoid calling replace several times, why don't you use the replace function with a regular expression and a replacement function, like the following piece of code? ([See here for the doc](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter)):
```js
exports.htmlEntitiesToUtf8 = function(inputText) {
   return inputText.replace(/&(#[xX]?)?[A-Za-z0-9]+;/g, function (entity) {
      var replacementCode, entityName = entity.slice(1, -1); //cut off & and ;
      if (entityName.toLowerCase().substr(0, 2) === '#x') {
        replacementCode = parseInt(entityName.slice(2), 16);
      } else if (entityName.substr(0, 1) === '#') {
        replacementCode = parseInt(entityName.slice(1));
      } else if (NAMED_HTML_ENTITIES[entityName]) {
        //named entities
        replacementCode = NAMED_HTML_ENTITIES[entityName];
      } else {
        throw new Error('"' + entity + '" is not a valid HTML entity.');
      }
      return String.fromCharCode(replacementCode);
   });
}
```