gitdiff-parser
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

gitdiff-parser

A fast and reliable git diff parser.

Install

npm install gitdiff-parser

Usage

import gitDiffParser from 'gitdiff-parser';

gitDiffParser.parse(gitDiffText);

gitDiffText should be a diff output by git diff command.

API

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[];
};

Readme

Keywords

none

Package Sidebar

Install

npm i gitdiff-parser

Weekly Downloads

30,234

Version

0.3.1

License

MIT

Unpacked Size

13.7 kB

Total Files

5

Last publish

Collaborators

  • otakustay
  • ecomfe-core