Function unescape

  • Unescapes HTML entities in text.

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

    Parameters

    • str: string

      The string to unescape.

    • options: Partial<UnescapeOptions> = {}

      Options for unescaping.

    Returns string

    The unescaped string.

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

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

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

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

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