HTML ENTITY – Every Character VS. Just Unicode

function to_HTMLENTITY(s, is_everychar){ "use strict";
  var regex = true === is_everychar ? /./ug : /[\u0080-\u10FFFF]/ug
  return s.replace(regex, function(c){
    c = c.charCodeAt(0).toString(16).toUpperCase();
    c = ("0000" + c).substr(-4);
    c = "&#x" + c + ";";
    return c;
  });
}