From 6a97d712b55ad7f758c1251a7705c6709d841d54 Mon Sep 17 00:00:00 2001 From: PatrickSachs Date: Fri, 17 Apr 2020 17:02:05 +0200 Subject: [PATCH 1/2] added typescript definitions --- index.d.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..04d615a --- /dev/null +++ b/index.d.ts @@ -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; + } + + export interface IOtOpts { + 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(); +} From 0daf75a48704a1e48531aac39eabe62727c45103 Mon Sep 17 00:00:00 2001 From: PatrickSachs Date: Sat, 23 Jan 2021 23:14:21 +0100 Subject: [PATCH 2/2] fixed feedback --- index.d.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/index.d.ts b/index.d.ts index 04d615a..e7b9933 100644 --- a/index.d.ts +++ b/index.d.ts @@ -11,14 +11,14 @@ declare module "ot-diff" { /** * 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; + public transform(value: string, transform: OtDiff): string; + public insert(value: string, transform: OtDiff): string; + public delete(value: string, transform: OtDiff): string; + public replace(value: string, transform: OtDiff): string; + public noop(value: string, transform: OtDiff): string; } - export interface IOtOpts { + export interface OtOpts { newString: string; oldString: string; raw: boolean; @@ -45,7 +45,8 @@ declare module "ot-diff" { payload: string } | { action: 'noop' - }) & { opts?: IOtOpts }; + }) & { opts?: OtOpts }; - export default new Diff(); + const diff: Diff; + export default diff; }