/** Used to map HTML entities to characters. */ const htmlUnescapes = { '&amp;' : '&' , '&lt;' : '<' , '&gt;' : '>' , '&quot;' : '"' , '&#39;' : "'" } ; /** Used to match HTML entities and HTML characters. */ const reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g ; const reHasEscapedHtml = RegExp ( reEscapedHtml . source ) ; since category param { string } string returns { string } see escape example export function unescape ( string ) { return ( string && reHasEscapedHtml . test ( string ) ) ? string . replace ( reEscapedHtml , ( entity ) => htmlUnescapes [ entity ] ) : string ; }