Skip to content

Added typescript definitions #1

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 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
51 changes: 51 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
declare module "ot-diff" {
class Diff {
/**
* Generates the diff.
* @param oldString
* @param newString
* @param raw
*/
public diff(oldString: string, newString: string, raw?: boolean): OtDiff;

/**
* Applies a transform (`insert`, `delete`, `replace` or `noop`) based on the value of diff.action.
*/
public transform(value: string, tramsform: OtDiff): string;
public insert(value: string, tramsform: OtDiff): string;
public delete(value: string, tramsform: OtDiff): string;
public replace(value: string, tramsform: OtDiff): string;
public noop(value: string, tramsform: OtDiff): string;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can tramsform please be changed to transform?

}

export interface IOtOpts {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can this be renamed to just OtOpts to avoid Hungarian notation?

newString: string;
oldString: string;
raw: boolean;
changeStart: number;
changeFromEnd: number;
changeEndIndexNew: number;
changeEndIndexOld: number;
charsAdded: number;
charsRemoved: number;
}

export type OtDiff = ({
action: 'insert',
start: number,
payload: string
} | {
action: 'delete',
start: number,
remove: number
} | {
action: 'replace',
start: number,
remove: number,
payload: string
} | {
action: 'noop'
}) & { opts?: IOtOpts };

export default new Diff();
}