1 | [![Build Status](https://github.com/sergeyt/parse-diff/actions/workflows/ci.yml/badge.svg)](https://github.com/sergeyt/parse-diff/actions/workflows/ci.yml)
|
2 | [![Total downloads](https://img.shields.io/npm/dt/parse-diff.svg)](https://www.npmjs.com/package/parse-diff)
|
3 |
|
4 | [![NPM](https://nodei.co/npm/parse-diff.png?downloads=true&stars=true)](https://nodei.co/npm/parse-diff/)
|
5 |
|
6 | # parse-diff
|
7 |
|
8 | Simple unified diff parser for JavaScript
|
9 |
|
10 | ## JavaScript Usage Example
|
11 |
|
12 | ```javascript
|
13 | var parse = require('parse-diff');
|
14 | var diff = ''; // input diff string
|
15 | var files = parse(diff);
|
16 | console.log(files.length); // number of patched files
|
17 | files.forEach(function(file) {
|
18 | console.log(file.chunks.length); // number of hunks
|
19 | console.log(file.chunks[0].changes.length) // hunk added/deleted/context lines
|
20 | // each item in changes is a string
|
21 | console.log(file.deletions); // number of deletions in the patch
|
22 | console.log(file.additions); // number of additions in the patch
|
23 | });
|
24 | ```
|