jsdiff icon indicating copy to clipboard operation
jsdiff copied to clipboard

Unexpected diffLines result on a basic example

Open dperetti opened this issue 3 years ago • 3 comments

import * as Diff from 'diff'
const diff = Diff.diffLines('a\nb\nc', 'a\nb', { newlineIsToken: false })
console.log(diff)

yields:

[ { count: 1, value: 'a\n' },
  { count: 2, added: undefined, removed: true, value: 'b\nc' },
  { count: 1, added: true, removed: undefined, value: 'b' } ]
[ { count: 1, value: 'a\n' },
  { count: 2, added: undefined, removed: true, value: 'b\nc' },
  { count: 1, added: true, removed: undefined, value: 'b' } ]

I need to add a trailing \n to get the expected, simpler result.

import * as Diff from 'diff'
const diff = Diff.diffLines('a\nb\nc\n', 'a\nb\n', { newlineIsToken: false })
console.log(diff)
[ { count: 2, value: 'a\nb\n' },
  { count: 1, added: undefined, removed: true, value: 'c\n' } ]

dperetti avatar May 30 '21 07:05 dperetti