MCPcopy Create free account
hub / github.com/backnotprop/plannotator / detectSourceEol

Function detectSourceEol

packages/shared/source-save-node.ts:40–51  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

38}
39
40export function detectSourceEol(text: string): SourceFileEol {
41 const crlf = (text.match(/\r\n/g) ?? []).length;
42 const withoutCrlf = text.replace(/\r\n/g, "");
43 const loneCr = (withoutCrlf.match(/\r/g) ?? []).length;
44 const loneLf = (withoutCrlf.match(/\n/g) ?? []).length;
45 const lf = loneLf + loneCr;
46
47 if (crlf === 0 && lf === 0) return "none";
48 if (crlf > 0 && lf === 0) return "crlf";
49 if (crlf === 0 && lf > 0) return "lf";
50 return "mixed";
51}
52
53export function applySourceEolPolicy(text: string, eol: SourceFileEol): string {
54 const normalized = text.replace(/\r\n?/g, "\n");

Callers 2

readSourceFileSnapshotFunction · 0.85

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected