https://github.com/ecomfe/gitdiff-parser
A fast and reliable git diff parser.
https://github.com/ecomfe/gitdiff-parser
diff git
Last synced: 11 months ago
JSON representation
A fast and reliable git diff parser.
- Host: GitHub
- URL: https://github.com/ecomfe/gitdiff-parser
- Owner: ecomfe
- License: mit
- Created: 2017-09-21T07:08:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-12T16:54:28.000Z (about 3 years ago)
- Last Synced: 2025-06-23T06:49:00.633Z (12 months ago)
- Topics: diff, git
- Language: HTML
- Homepage:
- Size: 1.37 MB
- Stars: 64
- Watchers: 3
- Forks: 17
- Open Issues: 29
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# gitdiff-parser
A fast and reliable git diff parser.
## Install
```shell
npm install gitdiff-parser
```
## Usage
```js
import gitDiffParser from 'gitdiff-parser';
gitDiffParser.parse(gitDiffText);
```
`gitDiffText` should be a diff output by `git diff` command.
### API
```ts
export interface Change {
content: string;
type: 'insert' | 'delete' | 'normal';
isInsert?: boolean;
isDelete?: boolean;
isNormal?: boolean;
lineNumber?: number;
oldLineNumber?: number;
newLineNumber?: number;
}
export interface Hunk {
content: string;
oldStart: number;
newStart: number;
oldLines: number;
newLines: number;
changes: Change[];
}
export interface File {
hunks: Hunk[];
oldEndingNewLine: boolean;
newEndingNewLine: boolean;
oldMode: string;
newMode: string;
similarity?: number;
oldRevision: string;
newRevision: string;
oldPath: string;
newPath: string;
isBinary?: boolean;
type: 'add' | 'delete' | 'modify' | 'rename';
}
export default {
parse(source: string): File[];
};
```