kdiff
v1.0.7
Published
Module for comparing two txt files using longest common subsequence
Downloads
14
Readme
Kdiff
Module for comparing two txt files using longest common subsequence
basic setup
npm install
npm run build
test command
npm run test
cli command (run at root directory)
node ./lib/cli.js [file1 path] [file2 path]
or
npm run cli-test
cli return value format & sample
[file1 line#] [diff type] [file2 line#]
< (mark for delete line) [line content]
> (mark for add line) [line content]
1d0
< a
3,5c2
< c
< d
< e
---
> c
library return value format
Diff {
deleted: {
[line1]: [text string1],
[line2]: [text string2],
[line3]: [text string3],
...
},
added: {
[line1]: [text string1],
[line2]: [text string2],
[line3]: [text string3],
...
}
}
Available as an npm module
how to setup on your project
npm install kdiff
basic implementation
1. sample code (on index.js)
const {diff} = require('kdiff');
var result = diff('[file1 path]', '[file2path]');
console.log(result);
console.log(result.deleted);
console.log(result.added);
2. run code
node index.js
3. sample output
Diff {
deleted: { '1': 'a', '3': 'c', '5': 'e' },
added: { '3': 'e', '4': 'f' }
}
{ '1': 'a', '3': 'c', '5': 'e' }
{ '3': 'e', '4': 'f' }