escape

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

function

function escape(str: string): string

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

str: string

The string to escape.

Returns

The escaped string.

Example: Usage

import { escape } from "@ende/html/entities";
import { assertEquals } from "@ende/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("þð"), "þð");

Source