Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielduarte/diffparse
Simple parser for Diff files (unified diff format)
https://github.com/danielduarte/diffparse
diff parse parser patch tool unified-format
Last synced: 17 days ago
JSON representation
Simple parser for Diff files (unified diff format)
- Host: GitHub
- URL: https://github.com/danielduarte/diffparse
- Owner: danielduarte
- License: mit
- Created: 2020-06-05T20:14:14.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-13T00:26:23.000Z (about 2 years ago)
- Last Synced: 2024-08-11T03:18:07.652Z (5 months ago)
- Topics: diff, parse, parser, patch, tool, unified-format
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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',
fileMode: 'new file mode 100644',
oldMode: null,
newMode: null,
index: 'index 0000000..2ccbe46',
oldFile: '--- /dev/null',
newFile: '+++ 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).