MCPcopy Create free account
hub / github.com/cloudflare/computer / detectLineEnding

Function detectLineEnding

packages/computer/src/tools/fs/edit-diff.ts:12–18  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

10// ---------- line endings & BOM ----------
11
12export function detectLineEnding(content: string): "\r\n" | "\n" {
13 const crlfIdx = content.indexOf("\r\n");
14 const lfIdx = content.indexOf("\n");
15 if (lfIdx === -1) return "\n";
16 if (crlfIdx === -1) return "\n";
17 return crlfIdx < lfIdx ? "\r\n" : "\n";
18}
19
20export function normalizeToLF(text: string): string {
21 return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");

Callers 1

createEditToolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected