For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/string/unescape.md.

unescape es-toolkit

Converts HTML entity characters to their original characters.

const result = unescape(str);

Usage

unescape(str)

Use unescape when you want to convert HTML entity characters back to their original characters. It converts HTML entities like &amp;, &lt;, &gt;, &quot;, &#39; to &, <, >, ", ' characters. This is the inverse operation of the escape function.

import { unescape } from 'es-toolkit/string';

// Convert HTML tag entities to original characters
unescape('This is a &lt;div&gt; element.');
// Returns: 'This is a <div> element.'

// Convert quote entities to original characters
unescape('This is a &quot;quote&quot;');
// Returns: 'This is a "quote"'

// Convert single quote entities to original characters
unescape('This is a &#39;quote&#39;');
// Returns: 'This is a 'quote''

// Convert ampersand entities to original characters
unescape('This is a &amp; symbol');
// Returns: 'This is a & symbol'

Useful when processing data from HTML forms or URLs:

// Convert HTML entities from user input
const userInput = 'My favorite tag is &lt;button&gt;';
const converted = unescape(userInput);
console.log(converted); // 'My favorite tag is <button>'

// Can also convert strings with mixed entities
const mixed = '&quot;Hello &amp; Welcome&quot; &lt;says the &gt; user';
const result = unescape(mixed);
console.log(result); // '"Hello & Welcome" <says the > user'

Parameters

strstringrequired

The string to convert.

Returns

Returns a string with HTML entities converted to their original characters.

string
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.