Skip to content

Fix types #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,32 @@ gitDiffParser.parse(gitDiffText);
### API

```ts
export interface Change {
export interface InsertChange {
type: 'insert';
content: string;
type: 'insert' | 'delete' | 'normal';
isInsert?: boolean;
isDelete?: boolean;
isNormal?: boolean;
lineNumber?: number;
oldLineNumber?: number;
newLineNumber?: number;
lineNumber: number;
isInsert: true;
}

export interface DeleteChange {
type: 'delete';
content: string;
lineNumber: number;
isDelete: true;
}

export interface NormalChange {
type: 'normal';
content: string;
isNormal: true;
oldLineNumber: number;
newLineNumber: number;
}

export type Change = InsertChange | DeleteChange | NormalChange;

export type ChangeType = Change['type'];

export interface Hunk {
content: string;
oldStart: number;
Expand All @@ -41,6 +56,8 @@ export interface Hunk {
changes: Change[];
}

export type FileType = 'add' | 'delete' | 'modify' | 'rename' | 'copy';

export interface File {
hunks: Hunk[];
oldEndingNewLine: boolean;
Expand All @@ -53,10 +70,10 @@ export interface File {
oldPath: string;
newPath: string;
isBinary?: boolean;
type: 'add' | 'delete' | 'modify' | 'rename';
type: FileType;
}

export default {
parse(source: string): File[];
};
export function parse(source: string): File[];

export as namespace gitDiffParser;
```
10 changes: 5 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export type ChangeType = 'insert' | 'delete' | 'normal';

export interface InsertChange {
type: 'insert';
content: string;
Expand All @@ -24,6 +22,8 @@ export interface NormalChange {

export type Change = InsertChange | DeleteChange | NormalChange;

export type ChangeType = Change['type'];

export interface Hunk {
content: string;
oldStart: number;
Expand All @@ -50,6 +50,6 @@ export interface File {
type: FileType;
}

export default {
parse(source: string): File[];
};
export function parse(source: string): File[];

export as namespace gitDiffParser;