File size: 584 Bytes
0f821de
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
/** Tag-safe JSON serialization for the model-visible reference envelope. */

/**
 * Serialize JSON while preventing source data from spelling an XML-like opening tag.
 * @param value - JSON-compatible reference data.
 * @returns JSON whose parse result is unchanged and whose data contains no literal `<`.
 */
export function stringifyTagSafeJson(value: unknown): string {
  const serialized: unknown = JSON.stringify(value)
  if (typeof serialized !== 'string') throw new TypeError('session-reference data is not JSON-serializable')
  return serialized.replaceAll('<', '\\u003c')
}