fix(diff): update diffArrays return value type to support arrays (#24869)

This commit is contained in:
Jack
2018-04-11 03:28:26 +10:00
committed by Mohamed Hegazy
parent e42e0bde81
commit bd402d4157
2 changed files with 18 additions and 3 deletions

View File

@@ -5,8 +5,16 @@ const other = 'beep boob blah';
let diff = jsdiff.diffChars(one, other);
printDiff(diff);
diff = jsdiff.diffArrays(['a', 'b', 'c'], ['a', 'c', 'd']);
printDiff(diff);
const diffArraysResult = jsdiff.diffArrays<string>(['a', 'b', 'c'], ['a', 'c', 'd']);
diffArraysResult.forEach(result => {
if (result.added) {
console.log(`added ${result.value.length} line(s):`, ...result.value);
} else if (result.removed) {
console.log(`removed ${result.value.length} line(s):`, ...result.value);
} else {
console.log(`no changes`);
}
});
// --------------------------

View File

@@ -29,6 +29,13 @@ declare namespace JsDiff {
removed?: boolean;
}
interface IDiffArraysResult<T> {
value: T[];
count?: number;
added?: boolean;
removed?: boolean;
}
interface IBestPath {
newPos: number;
componenets: IDiffResult[];
@@ -85,7 +92,7 @@ declare namespace JsDiff {
function diffSentences(oldStr: string, newStr: string, options?: IOptions): IDiffResult[];
function diffArrays(oldArr: any[], newArr: any[], options?: IArrayOptions): IDiffResult[];
function diffArrays<T>(oldArr: T[], newArr: T[], options?: IArrayOptions): Array<IDiffArraysResult<T>>;
function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string;