MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / countDiffStats

Function countDiffStats

shared/utils/diff.ts:365–393  ·  view source on GitHub ↗
(hunks: (DiffHunk | DiffSkipBlock)[])

Source from the content-addressed store, hash-verified

363}
364
365export function countDiffStats(hunks: (DiffHunk | DiffSkipBlock)[]): {
366 additions: number
367 deletions: number
368} {
369 let additions = 0
370 let deletions = 0
371
372 for (const hunk of hunks) {
373 if (hunk.type === 'hunk') {
374 for (const line of hunk.lines) {
375 if (line.type === 'insert') additions++
376 else if (line.type === 'delete') deletions++
377 else if (line.type === 'normal') {
378 // Merged modified lines have type 'normal' but contain inline
379 // insert/delete segments. Count them as both an addition and deletion.
380 const hasInlineChanges = line.content.some(
381 seg => seg.type === 'insert' || seg.type === 'delete',
382 )
383 if (hasInlineChanges) {
384 additions++
385 deletions++
386 }
387 }
388 }
389 }
390 }
391
392 return { additions, deletions }
393}

Callers 1

[...pkg].get.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected