mikiya1130 / gitdiff-parser

A fast and reliable git diff parser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

A fast and reliable git diff parser.

License:MIT License


Languages

Language:HTML 99.5%Language:JavaScript 0.5%