MCPcopy Create free account
hub / github.com/vitest-dev/vitest / joinAlignedDiffsExpand

Function joinAlignedDiffsExpand

packages/utils/src/diff/joinAlignedDiffs.ts:299–320  ·  view source on GitHub ↗
(
  diffs: Array<Diff>,
  options: DiffOptionsNormalized,
)

Source from the content-addressed store, hash-verified

297// Given array of aligned strings with inverse highlight formatting,
298// return joined lines with diff formatting.
299export function joinAlignedDiffsExpand(
300 diffs: Array<Diff>,
301 options: DiffOptionsNormalized,
302): string {
303 return diffs
304 .map((diff: Diff, i: number, diffs: Array<Diff>): string => {
305 const line = diff[1]
306 const isFirstOrLast = i === 0 || i === diffs.length - 1
307
308 switch (diff[0]) {
309 case DIFF_DELETE:
310 return printDeleteLine(line, isFirstOrLast, options)
311
312 case DIFF_INSERT:
313 return printInsertLine(line, isFirstOrLast, options)
314
315 default:
316 return printCommonLine(line, isFirstOrLast, options)
317 }
318 })
319 .join('\n')
320}

Callers 1

printDiffLinesFunction · 0.90

Calls 3

printDeleteLineFunction · 0.85
printInsertLineFunction · 0.85
printCommonLineFunction · 0.85

Tested by

no test coverage detected