Skip to content

unescapeHtml

Unescapes the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; back to &, <, >, ", and '.

This is the exact inverse of escapeHtml — it only recognizes the five entities that function produces, not the full HTML entity set (no &nbsp;, no numeric code points beyond &#39;, etc.).

Available since v3.0.0

import { unescapeHtml } from '@helpers4/string';
// or, from the all-in-one package (same code, one install):
import { unescapeHtml } from 'helpers4/string';
unescapeHtml(str: string): string
ParameterTypeDescription
strstringThe string to unescape

string — The unescaped string

Unescape HTML entities back to their original characters

Section titled “Unescape HTML entities back to their original characters”

Inverse of escapeHtml — turns <, >, &, ”, ’ back into < > & ” ’.

unescapeHtml('&lt;b&gt;bold&lt;/b&gt;')
// => '<b>bold</b>'

Only the five entities escapeHtml produces are unescaped — not the full HTML entity set.

unescapeHtml('a&nbsp;b')
// => 'a&nbsp;b'  (unchanged)

View source on GitHub