MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / computeDiffStats

Function computeDiffStats

src/utils/diff.ts:12–25  ·  view source on GitHub ↗
(oldContent: string, newContent: string)

Source from the content-addressed store, hash-verified

10}
11
12export function computeDiffStats(oldContent: string, newContent: string): DiffStats {
13 const changes = diffLines(oldContent, newContent);
14 let additions = 0;
15 let deletions = 0;
16 for (const change of changes) {
17 // Use the diff library's own line count. Counting '\n' characters
18 // under-counts a final line with no trailing newline (a new file or an
19 // append with no terminating newline), reporting 0 for a real change.
20 const lineCount = change.count ?? (change.value.match(/\n/g) ?? []).length;
21 if (change.added) additions += lineCount;
22 if (change.removed) deletions += lineCount;
23 }
24 return { additions, deletions };
25}
26
27export interface ColoredDiffLine {
28 type: 'add' | 'del' | 'context' | 'hunk';

Callers 1

diff-stats.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected