Parse me a numeric html entity

Matt Ellen - Aug 30 '19 - - Dev Community

I saw the following question:

I am using wordpress rest api and am getting encoded title strings from the server. I want to decode the string before I use it to replace the document.title.

Wordpress api

{
 "id": 698,
 "title": {
  "rendered": "Ludovico Einaudi – “Divenire”"
 },
}

actions.js

export default {
  updateDocTitle ({ state,

It's been closed as a dupe, but that didn't discourage me from wanting to figure it out for myself.

So, the challenge is: for any given string input, replace any numerically represented html entities with the correct character.

Remember, the largest codepoint is 0x10ffff.

Some test cases:

'ö_ö' // expected 'ö_ö'
'Hello &&&#x;'  // expected 'Hello &&&#x;'
'&#x123 ģ'  // expected '&#x123 ģ'
'�'    // expected '�'
Enter fullscreen mode Exit fullscreen mode

I'll post my attempt below!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .