@@ -8,6 +8,7 @@ export enum DiffType {
88 REMOVED = 2 ,
99}
1010
11+ // See https://github.com/kpdecker/jsdiff/tree/v4.0.1#api for more info on the below JsDiff methods
1112export enum DiffMethod {
1213 CHARS = 'diffChars' ,
1314 WORDS = 'diffWords' ,
@@ -19,8 +20,6 @@ export enum DiffMethod {
1920}
2021
2122export interface DiffInformation {
22- added ?: boolean ;
23- removed ?: boolean ;
2423 value ?: string | DiffInformation [ ] ;
2524 lineNumber ?: number ;
2625 type ?: DiffType ;
@@ -41,6 +40,13 @@ export interface ComputedDiffInformation {
4140 right ?: DiffInformation [ ] ;
4241}
4342
43+ // See https://github.com/kpdecker/jsdiff/tree/v4.0.1#change-objects for more info on JsDiff Change Objects
44+ export interface JsDiffChangeObject {
45+ added ?: boolean ;
46+ removed ?: boolean ;
47+ value ?: string ;
48+ }
49+
4450/**
4551 * Splits diff text by new line and computes final list of diff lines based on
4652 * conditions.
@@ -78,16 +84,16 @@ const constructLines = (value: string): string[] => {
7884 *
7985 * @param oldValue Old word in the line.
8086 * @param newValue New word in the line.
81- * @param jsDiffCompareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
87+ * @param compareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
8288 */
83- const computeDiff = ( oldValue : string , newValue : string , jsDiffCompareMethod : string ) : ComputedDiffInformation => {
84- const diffArray = jsDiff [ jsDiffCompareMethod ] ( oldValue , newValue ) ;
89+ const computeDiff = ( oldValue : string , newValue : string , compareMethod : string ) : ComputedDiffInformation => {
90+ const diffArray : Array < JsDiffChangeObject > = jsDiff [ compareMethod ] ( oldValue , newValue ) ;
8591 const computedDiff : ComputedDiffInformation = {
8692 left : [ ] ,
8793 right : [ ] ,
8894 } ;
8995 diffArray
90- . forEach ( ( { added, removed, value } : DiffInformation ) : DiffInformation => {
96+ . forEach ( ( { added, removed, value } ) : DiffInformation => {
9197 const diffInformation : DiffInformation = { } ;
9298 if ( added ) {
9399 diffInformation . type = DiffType . ADDED ;
@@ -121,13 +127,13 @@ const computeDiff = (oldValue: string, newValue: string, jsDiffCompareMethod: st
121127 * @param oldString Old string to compare.
122128 * @param newString New string to compare with old string.
123129 * @param disableWordDiff Flag to enable/disable word diff.
124- * @param jsDiffCompareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
130+ * @param compareMethod JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
125131 */
126132const computeLineInformation = (
127133 oldString : string ,
128134 newString : string ,
129135 disableWordDiff : boolean = false ,
130- jsDiffCompareMethod : string = DiffMethod . CHARS ,
136+ compareMethod : string = DiffMethod . CHARS ,
131137) : ComputedLineInformation => {
132138 const diffArray = diff . diffLines (
133139 oldString . trimRight ( ) ,
@@ -190,10 +196,10 @@ const computeLineInformation = (
190196 right . type = type ;
191197 // Do word level diff and assign the corresponding values to the
192198 // left and right diff information object.
193- if ( disableWordDiff || ! ( < any > Object ) . values ( DiffMethod ) . includes ( jsDiffCompareMethod ) ) {
199+ if ( disableWordDiff || ! ( < any > Object ) . values ( DiffMethod ) . includes ( compareMethod ) ) {
194200 right . value = rightValue ;
195201 } else {
196- const computedDiff = computeDiff ( line , rightValue as string , jsDiffCompareMethod ) ;
202+ const computedDiff = computeDiff ( line , rightValue as string , compareMethod ) ;
197203 right . value = computedDiff . right ;
198204 left . value = computedDiff . left ;
199205 }
0 commit comments