πŸ“„ File detail

utils/xml.ts

🧩 .tsπŸ“ 17 linesπŸ’Ύ 622 bytesπŸ“ text
← Back to All Files

🎯 Use case

This file lives under β€œutils/”, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, …). On the API surface it exposes escapeXml and escapeXmlAttr β€” mainly functions, hooks, or classes. What the file header says: Escape XML/HTML special characters for safe interpolation into element text content (between tags). Use when untrusted strings (process stdout, user input, external data) go inside `<tag>${here}</tag>`.

Generated from folder role, exports, dependency roots, and inline comments β€” not hand-reviewed for every path.

🧠 Inline summary

Escape XML/HTML special characters for safe interpolation into element text content (between tags). Use when untrusted strings (process stdout, user input, external data) go inside `<tag>${here}</tag>`.

πŸ“€ Exports (heuristic)

  • escapeXml
  • escapeXmlAttr

πŸ–₯️ Source preview

/**
 * Escape XML/HTML special characters for safe interpolation into element
 * text content (between tags). Use when untrusted strings (process stdout,
 * user input, external data) go inside `<tag>${here}</tag>`.
 */
export function escapeXml(s: string): string {
  return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
}

/**
 * Escape for interpolation into a double- or single-quoted attribute value:
 * `<tag attr="${here}">`. Escapes quotes in addition to `& < >`.
 */
export function escapeXmlAttr(s: string): string {
  return escapeXml(s).replace(/"/g, '&quot;').replace(/'/g, '&apos;')
}