This should work for the vast majority of cases:
function unicodeHtmlEntity (t) {
var numericValue = parseInt(t.slice(2, -1), 10);
return String.fromCharCode(numericValue);
}
If you actually need to support characters in the "astral" planes, you can use: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint#Getting_it_to_work_with_higher_values in place of String.fromCharCode()
.
I presume you are aware that your code does not deal with hexadecimal entities, only decimal ones. To support those you could do something like:
function unicodeHtmlEntity (t) {
var hex = t.charAt(2) === 'x';
var base = hex ? 16 : 10;
var pos = hex ? 3 : 2;
var numericValue = parseInt(t.slice(pos, -1), base);
return String.fromCharCode(numericValue);
}