Skip to content

Html

HTML utility functions for escaping and working with HTML content.

Import

typescript
import { Html } from '@wollybeard/kit'
typescript
import * as Html from '@wollybeard/kit/html'

Functions

[F] escape

typescript
(string: unknown): string

Parameters:

  • string - The string to escape (will be coerced to string if not already)

Returns: The escaped string safe for use in HTML

Escape HTML special characters to prevent XSS vulnerabilities.

Converts the following characters to their HTML entity equivalents:

  • ""
  • ''
  • &&
  • <&lt;
  • >&gt;

Examples:

typescript
Html
.escape('Use Array<T> or Record<K, V>')
// => 'Use Array&lt;T&gt; or Record&lt;K, V&gt;'
Html
.escape('<script>alert("xss")</script>')
// => '&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;'