Skip to main content

unescape

Converts the HTML entities & < > " ' back to their original characters. It is the inverse of escape.

Only the five entities produced by escape are converted, and leading 0s in numeric references are ignored. (''' → "'") Other entities ( , ', etc.) are left untouched.


Code​

🔗 View source code


Interface​

typescript
function unescape(str: string): string;

Usage​

typescript
import { unescape } from '@modern-kit/utils';

unescape('This is a &lt;div&gt; element.'); // 'This is a <div> element.'
unescape('This is a &quot;quote&quot;'); // 'This is a "quote"'
unescape('This is a &#39;quote&#39;'); // "This is a 'quote'"
unescape('This is a &amp; symbol'); // 'This is a & symbol'

// Scans the string only once, so converted results are not converted again
unescape('&amp;lt;'); // '&lt;'