Function escape

  • Escapes text for safe interpolation into HTML text content and quoted attributes.

    Parameters

    • str: string

      The string to escape.

    Returns string

    The escaped string.

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

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

    // Characters that don't need to be escaped will be left alone,
    // even if named HTML entities exist for them.
    assertEquals(escape("þð"), "þð");