@noname-land/parse-diff
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@noname-land/parse-diff

npm

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @noname-land/parse-diff

Weekly Downloads

1

Version

1.0.0

License

none

Unpacked Size

6.58 kB

Total Files

5

Last publish

Collaborators

  • igoradamenko