# @tandil/diffparse

> Simple parser for Diff files (unified diff format)

Latest version **0.2.0** (published 2020-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tandil/diffparse
pnpm add @tandil/diffparse
yarn add @tandil/diffparse
bun add @tandil/diffparse
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2020-06-07 |
| First published | 2020-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Daniel Duarte |
| Maintainers | danielduarte |
| Keywords | diff, parser, parse, patch, unified-format, tool |

## Links

- npm: https://www.npmjs.com/package/@tandil/diffparse
- Repository: https://github.com/danielduarte/diffparse
- Homepage: https://github.com/danielduarte/diffparse#readme
- Issues: https://github.com/danielduarte/diffparse/issues
- npm.io page: https://npm.io/package/@tandil/diffparse

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2020-06-07
- 0.1.2 — 2020-06-06
- 0.1.1 — 2020-06-05
- 0.1.0 — 2020-06-05

## README

# @tandil/diffparse
[![NPM Package Version](https://img.shields.io/npm/v/@tandil/diffparse)](https://www.npmjs.com/package/@tandil/diffparse)
[![License](https://img.shields.io/npm/l/@tandil/diffparse?color=%23007ec6)](https://github.com/danielduarte/diffparse/blob/master/LICENSE)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-blue.svg)](https://conventionalcommits.org)

Simple parser for Diff files (unified diff format)

## Features

- Parse a diff file from its filepath
- Parse a diff directly from a string
- Error reporting: If there are parsing errors, the partial result is returned and the list of detected errors including line numbers

## Usage

### Parse from file

#### Async with Promises

Given a filepath it returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves to a JS object with the diff content parsed and easily accessible programmatically.

```js
const parser = require('@tandil/diffparse');

parser.parseDiffFile('./examples/example1.diff').then(diff => {
  console.log(diff);
});
```

#### Sync

```js
const parser = require('@tandil/diffparse');

const diff = parser.parseDiffFileSync('./examples/example1.diff');
console.log(diff);
```

### Parse from string

Given a diff string it returns a JS object with the diff content parsed and easily accessible programmatically.

```js
const parser = require('@tandil/diffparse');

const diffStr = `diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2ccbe46
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/node_modules/`;

const diff = parser.parseDiffString(diffStr);

console.log(diff);
```

Outputs

```js
{
  header: [],
  files: [
    {
      header: 'diff --git a/.gitignore b/.gitignore',
      mode: 'new file mode 100644',
      index: 'index 0000000..2ccbe46',
      old: '--- /dev/null',
      new: '+++ b/.gitignore',
      chunks: [
        {
          header: '@@ -0,0 +1 @@',
          content: [
            '+/node_modules/'
          ]
        }
      ]
    }
  ],
  errors: []
}
```

## Having issues?

Feel free to report any issues or feature request in [Github repo](https://github.com/danielduarte/diffparse/issues/new).

---
_Source: https://npm.io/package/@tandil/diffparse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
