unescape

import { unescape } from "jsr:@ende/html";

function

function unescape(str: string, options: Partial<UnescapeOptions> = [UNSUPPORTED]): string

Unescapes HTML entities in text.

Default options only handle &<>'" and numeric entities.

str: string

The string to unescape.

options: Partial<UnescapeOptions> = [UNSUPPORTED]

Options for unescaping.

Returns

The unescaped string.

Example: Basic usage

import { unescape } from "@ende/html/entities";
import { assertEquals } from "@ende/assert";

assertEquals(unescape("&lt;&gt;&#39;&amp;AA"), "<>'&AA");
assertEquals(unescape("&thorn;&eth;"), "&thorn;&eth;");

Example: Using a custom entity list

This uses the full named entity list from the HTML spec (~47K un-minified)

import { unescape } from "@ende/html/entities";
import entityList from "@ende/html/named-entity-list.json" with { type: "json" };
import { assertEquals } from "@ende/assert";

assertEquals(unescape("&lt;&gt;&#39;&amp;AA", { entityList }), "<>'&AA");

Source