Browse API packages

API · v0.17.0

html

Standard library HTML

Member signatures use schematic object.member(...) API notation. Exported type declarations are valid TypeScript.

Browser-safe HTML text encoding utilities.

These utilities have no runtime-native dependencies and work in current browsers, Node, Deno, and Bun.

ts
import HTML from "@rcompat/html";

HTML.escape#

Escapes a string for HTML text or a quoted HTML attribute value.

Replaces &, <, >, ", and ' with HTML entities. HTML encoding is context-specific: this does not make input safe for JavaScript, CSS, unquoted attributes, or URL protocols. Validate URLs and other structured values before encoding them.

Parameters

  • input — String to escape.

Returns: The HTML-encoded string.

ts
HTML.escape(input: string): string;

Example

ts
HTML.escape('<span title="me & you">');
// "&lt;span title=&quot;me &amp; you&quot;&gt;"