-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.d.ts
181 lines (161 loc) · 4.04 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
export interface ILCSResult {
buffer1index: number;
buffer2index: number;
chain: null | ILCSResult;
}
/**
* Expects two arrays, finds longest common sequence
* @param {T[]} buffer1
* @param {T[]} buffer2
* @returns {ILCSResult}
* @constructor
*/
export function LCS<T>(buffer1: T[], buffer2: T[]): ILCSResult;
export interface ICommResult<T> {
buffer1: T[];
buffer2: T[];
}
/**
* We apply the LCS to build a 'comm'-style picture of the
* differences between buffer1 and buffer2.
* @param {T[]} buffer1
* @param {T[]} buffer2
* @returns {Array<ICommResult<T>>}
*/
export function diffComm<T>(buffer1: T[], buffer2: T[]): ICommResult<T>[];
export interface IDiffIndicesResult<T> {
buffer1: [number, number];
buffer1Content: T[];
buffer2: [number, number];
buffer2Content: T[];
}
/**
* We apply the LCS to give a simple representation of the
* offsets and lengths of mismatched chunks in the input
* buffers. This is used by diff3MergeRegions.
* @param {T[]} buffer1
* @param {T[]} buffer2
* @returns {IDiffIndicesResult<T>[]}
*/
export function diffIndices<T>(
buffer1: T[],
buffer2: T[]
): IDiffIndicesResult<T>[];
export interface IChunk<T> {
offset: number;
length: number;
chunk: T[];
}
export interface IPatchRes<T> {
buffer1: IChunk<T>;
buffer2: IChunk<T>;
}
/**
* We apply the LCS to build a JSON representation of a
* diff(1)-style patch.
* @param {T[]} buffer1
* @param {T[]} buffer2
* @returns {IPatchRes<T>[]}
*/
export function diffPatch<T>(buffer1: T[], buffer2: T[]): IPatchRes<T>[];
export function patch<T>(buffer: T[], patch: IPatchRes<T>[]): T[];
export interface IStableRegion<T> {
stable: true;
buffer: 'a' | 'o' | 'b';
bufferStart: number;
bufferLength: number;
bufferContent: T[];
}
export interface IUnstableRegion<T> {
stable: false;
aStart: number;
aLength: number;
aContent: T[];
bStart: number;
bLength: number;
bContent: T[];
oStart: number;
oLength: number;
oContent: T[];
}
export type IRegion<T> = IStableRegion<T> | IUnstableRegion<T>;
/**
* Given three buffers, A, O, and B, where both A and B are
* independently derived from O, returns a fairly complicated
* internal representation of merge decisions it's taken. The
* interested reader may wish to consult
*
* Sanjeev Khanna, Keshav Kunal, and Benjamin C. Pierce.
* 'A Formal Investigation of ' In Arvind and Prasad,
* editors, Foundations of Software Technology and Theoretical
* Computer Science (FSTTCS), December 2007.
*
* (http://www.cis.upenn.edu/~bcpierce/papers/diff3-short.pdf)
*
* @param {T[]} a
* @param {T[]} o
* @param {T[]} b
* @returns {IRegion<T>[]}
*/
export function diff3MergeRegions<T>(a: T[], o: T[], b: T[]): IRegion<T>[];
export interface MergeRegion<T> {
ok?: T[];
conflict?: {
a: T[];
aIndex: number;
b: T[];
bIndex: number;
o: T[];
oIndex: number;
};
}
export interface MergeResult {
conflict: boolean;
result: string[];
}
export interface IMergeOptions {
excludeFalseConflicts?: boolean;
stringSeparator?: string | RegExp;
}
/**
* Applies the output of diff3MergeRegions to actually
* construct the merged buffer; the returned result alternates
* between 'ok' and 'conflict' blocks.
* A "false conflict" is where `a` and `b` both change the same from `o`
*
* @param {string | T[]} a
* @param {string | T[]} o
* @param {string | T[]} b
* @param {{excludeFalseConflicts: boolean; stringSeparator: RegExp}} options
* @returns {MergeRegion<T>[]}
*/
export function diff3Merge<T>(
a: string | T[],
o: string | T[],
b: string | T[],
options?: IMergeOptions
): MergeRegion<T>[];
export function merge<T>(
a: string | T[],
o: string | T[],
b: string | T[],
options?: IMergeOptions
): MergeResult;
export function mergeDiff3<T>(
a: string | T[],
o: string | T[],
b: string | T[],
options?: IMergeOptions & {
label?: {
a?: string;
o?: string;
b?: string;
}
}
): MergeResult;
export function mergeDigIn<T>(
a: string | T[],
o: string | T[],
b: string | T[],
options?: IMergeOptions
): MergeResult;