const cache = { } ; export function getLiteralText ( text ) { if ( cache [ text ] ) { return cache [ text ] ; } const el = document . createElement ( 'div' ) ; el . innerHTML = text ; cache [ text ] = el . textContent ; return cache [ text ] ; } const keys = [ '&nbsp;' , '&lt;' , '&gt;' , '&amp;' , '&apos;' , '&ensp;' , '&emsp;' ] ; const replaceEncodeReg = new RegExp ( keys . join ( '|' ) , 'g' ) ; export function decode ( str ) { return str . replace ( replaceEncodeReg , m => getLiteralText ( m ) ) ; }