escape
Converts any value a JSX child may hold to escaped HTML: the helper compiled server output calls for every dynamic child, and what the renderers call on the app's result.
Converts any value a JSX child may hold to escaped HTML: the helper compiled server output calls for every dynamic child, and what the renderers call on the app's result.
- Strings are escaped (
& < > " '); numbers and bigints are written as they are;null,undefinedand booleans render nothing. SsrNodevalues (fromssr,ssrRawand the other helpers) pass through unchanged: they were escaped when they were built.- Accessors are called (untracked) and their result is rendered; a chain of more than 1000 accessors returning accessors throws.
- Arrays are flattened in order, with an explicit stack, so nesting depth is not limited by the call stack.
- Plain objects throw in development builds and render nothing in production builds.
Import#
ts
import { escape } from "@shadow-js/web/server";
Signature#
ts
function escape(value: unknown): string
Parameters#
| Name | Description |
|---|---|
value |
The value to render. |
Returns#
The escaped markup.
Throws#
- TypeError when an array contains itself, for a symbol (
UNRECOGNIZED_INSERT_VALUE), for an object that is not anSsrNode(UNRECOGNIZED_INSERT_VALUE, development builds only), and for an accessor chain deeper than 1000.
Examples#
ts
import { escape } from "@shadow-js/web/server";
const name = () => "<Ada>";
escape(["Hello, ", name, null, 3]); // "Hello, <Ada>3"