1const ESCAPE_SCRIPT_DATA = /</g
2
3const ESCAPE_LINE_TERMS = /[\u2028\u2029]/g
4
5/**
6 * @internal
7 */
8export function escapeJson(spec: unknown): string {
9 return JSON.stringify(spec)
10 .replace(ESCAPE_SCRIPT_DATA, "\\u003c")
11 .replace(ESCAPE_LINE_TERMS, (c) => c === "\u2028" ? "\\u2028" : "\\u2029")
12}
13
14/**
15 * @internal
16 */
17export function escape(str: string): string {
18 return str
19 .replace(/&/g, "&amp;")
20 .replace(/</g, "&lt;")
21 .replace(/>/g, "&gt;")
22}
23
24/**
25 * @internal
26 */
27export function escapeAttribute(str: string): string {
28 return escape(str)
29 .replace(/"/g, "&quot;")
30 .replace(/'/g, "&#39;")
31}