Return unchanged lines in a patch?
I want to use this library to change the difference between the two files. But I need to show all file's content, not only changed one. Right now the library's call Diff.createPatch returns only changed part of the file, can it return all lines? Something like doing this command diff -U 1000000 file1.txt file2.txt from here: How can I diff two files with full context?
Thank you.
You can use Diff.structuredPatch() which returns a data structure including all lines.
As you can see in the "README.md", the array "lines" contains unchanged, removed(-) and inserted(+) lines.
hunks: [{
oldStart: 1, oldLines: 3, newStart: 1, newLines: 3,
lines: [' line2', ' line3', '-line4', '+line5', '\\ No newline at end of file'],
}]
it is does not work ..can supply a example
I used {context: Number.MAX_SAFE_INTEGER} as option in Diff.createTwoFilesPatch to include all unchanged lines, this should work for Diff.createPatch too.
Can anyone provide the syntax here to add options?
Yes, passing {context: Number.MAX_SAFE_INTEGER} or {context: Infinity} as the value of the options argument to createPatch (or structuredPatch or createTwoFilesPatch) will do the trick here.
(You could also just use diffLines if you're okay working with jsdiff change objects instead of unified diff patches. jsdiff's arrays of change objects always include all the unchanged lines.)