jsonLdText
Writes a JSON-LD value as safe script text: <, >, & and the line separators become escapes.
Writes a JSON-LD value as safe script text: <, >, & and the line separators become escapes.
Import#
ts
import { jsonLdText } from "@shadow-js/dusk";
Signature#
ts
function jsonLdText(value: unknown): string
Parameters#
| Name | Description |
|---|---|
value |
An object or an array, as JSON-LD requires. |
Returns#
The JSON text, safe to put in a script element.
Throws#
- TypeError when the value is not an object or an array.
- RangeError when the text is longer than
MAX_JSON_LD_LENGTH.
Examples#
ts
import { jsonLdText } from the "@shadow-js/dusk" subpath;
jsonLdText({ "@type": "Organization", name: "Example <beta>" }); // '{"@type":"Organization","name":"Example \u003cbeta\u003e"}'