1.0.0 • Published 5 years ago
@noname-land/parse-diff v1.0.0
@noname-land/parse-diff
Simple unified diff parser for Node.js.
Installation
npm i --save @noname-land/parse-diff
Usage
const parse = require('@noname-land/parse-diff');
const diff = `\
diff --git a/test b/test
deleted file mode 100644
index db81be4..0000000
--- b/test
+++ /dev/null
@@ -1,2 +0,0 @@
-line1
-line2\
`;
const files = parse(diff);
console.log(files.length); // number of changed files
files.forEach(file => {
// number of chunks
console.log(file.chunks.length);
// chunk added/deleted/unchanged lines
console.log(file.chunks[0].lines.length)
// number of deletions in the diff
console.log(file.deletions);
// number of additions in the diff
console.log(file.additions);
});
Note
This package is a fork of parse-diff by @sergeyt. It has been rewritten with ES6 and refactored to be more clear and readable.
The original package was published under MIT.
1.0.0
5 years ago