MCPcopy Create free account
hub / github.com/cloudflare/agents / escapeStringLiteral

Function escapeStringLiteral

packages/codemode/src/utils.ts:140–153  ·  view source on GitHub ↗
(s: string)

Source from the content-addressed store, hash-verified

138 * Escape a string for use inside a double-quoted TypeScript string literal.
139 */
140export function escapeStringLiteral(s: string): string {
141 let out = "";
142 for (const ch of s) {
143 if (ch === "\\") out += "\\\\";
144 else if (ch === '"') out += '\\"';
145 else if (ch === "\n") out += "\\n";
146 else if (ch === "\r") out += "\\r";
147 else if (ch === "\t") out += "\\t";
148 else if (ch === "\u2028") out += "\\u2028";
149 else if (ch === "\u2029") out += "\\u2029";
150 else out += escapeControlChar(ch);
151 }
152 return out;
153}
154
155/**
156 * Escape a string for use inside a JSDoc comment.

Callers 1

jsonSchemaToTypeStringFunction · 0.90

Calls 1

escapeControlCharFunction · 0.85

Tested by

no test coverage detected