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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
|
// Type definitions for diff 4.0
// Project: https://github.com/kpdecker/jsdiff
// Definitions by: vvakame <https://github.com/vvakame>
// szdc <https://github.com/szdc>
// moc-yuto <https://github.com/moc-yuto>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
export as namespace Diff;
export type Callback = (err: undefined, value?: Change[]) => void;
export interface CallbackOptions {
/**
* Callback to call with the result instead of returning the result directly.
*/
callback: Callback;
}
export interface BaseOptions {
/**
* `true` to ignore casing difference.
* @default false
*/
ignoreCase?: boolean;
}
export interface WordsOptions extends BaseOptions {
/**
* `true` to ignore leading and trailing whitespace. This is the same as `diffWords()`.
*/
ignoreWhitespace?: boolean;
}
export interface LinesOptions extends BaseOptions {
/**
* `true` to ignore leading and trailing whitespace. This is the same as `diffTrimmedLines()`.
*/
ignoreWhitespace?: boolean;
/**
* `true` to treat newline characters as separate tokens. This allows for changes to the newline structure
* to occur independently of the line content and to be treated as such. In general this is the more
* human friendly form of `diffLines()` and `diffLines()` is better suited for patches and other computer
* friendly output.
*/
newlineIsToken?: boolean;
}
export interface JsonOptions extends LinesOptions {
/**
* Replacer used to stringify the properties of the passed objects.
*/
stringifyReplacer?: (key: string, value: any) => any;
/**
* The value to use when `undefined` values in the passed objects are encountered during stringification.
* Will only be used if `stringifyReplacer` option wasn't specified.
* @default undefined
*/
undefinedReplacement?: any;
}
export interface ArrayOptions<TLeft, TRight> extends BaseOptions {
/**
* Comparator for custom equality checks.
*/
comparator?: (left: TLeft, right: TRight) => boolean;
}
export interface PatchOptions extends LinesOptions {
/**
* Describes how many lines of context should be included.
* @default 4
*/
context?: number;
}
export interface ApplyPatchOptions {
/**
* Number of lines that are allowed to differ before rejecting a patch.
* @default 0
*/
fuzzFactor?: number;
/**
* Callback used to compare to given lines to determine if they should be considered equal when patching.
* Should return `false` if the lines should be rejected.
*
* @default strict equality
*/
compareLine?: (
lineNumber: number,
line: string,
operation: '-' | ' ',
patchContent: string
) => boolean;
}
export interface ApplyPatchesOptions extends ApplyPatchOptions {
loadFile(index: ParsedDiff, callback: (err: any, data: string) => void): void;
patched(index: ParsedDiff, content: string, callback: (err: any) => void): void;
complete(err: any): void;
}
export interface Change {
count?: number;
/**
* Text content.
*/
value: string;
/**
* `true` if the value was inserted into the new string.
*/
added?: boolean;
/**
* `true` if the value was removed from the old string.
*/
removed?: boolean;
}
export interface ArrayChange<T> {
value: T[];
count?: number;
added?: boolean;
removed?: boolean;
}
export interface ParsedDiff {
index?: string;
oldFileName?: string;
newFileName?: string;
oldHeader?: string;
newHeader?: string;
hunks: Hunk[];
}
export interface Hunk {
oldStart: number;
oldLines: number;
newStart: number;
newLines: number;
lines: string[];
linedelimiters: string[];
}
export interface BestPath {
newPos: number;
componenets: Change[];
}
export class Diff {
diff(
oldString: string,
newString: string,
options?: Callback | (ArrayOptions<any, any> & Partial<CallbackOptions>)
): Change[];
pushComponent(components: Change[], added: boolean, removed: boolean): void;
extractCommon(
basePath: BestPath,
newString: string,
oldString: string,
diagonalPath: number
): number;
equals(left: any, right: any): boolean;
removeEmpty(array: any[]): any[];
castInput(value: any): any;
join(chars: string[]): string;
tokenize(value: string): any; // return types are string or string[]
}
/**
* Diffs two blocks of text, comparing character by character.
*
* @returns A list of change objects.
*/
export function diffChars(oldStr: string, newStr: string, options?: BaseOptions): Change[];
export function diffChars(
oldStr: string,
newStr: string,
options: Callback | (BaseOptions & CallbackOptions)
): void;
/**
* Diffs two blocks of text, comparing word by word, ignoring whitespace.
*
* @returns A list of change objects.
*/
export function diffWords(oldStr: string, newStr: string, options?: WordsOptions): Change[];
export function diffWords(
oldStr: string,
newStr: string,
options: Callback | (WordsOptions & CallbackOptions)
): void;
/**
* Diffs two blocks of text, comparing word by word, treating whitespace as significant.
*
* @returns A list of change objects.
*/
export function diffWordsWithSpace(
oldStr: string,
newStr: string,
options?: WordsOptions
): Change[];
export function diffWordsWithSpace(
oldStr: string,
newStr: string,
options: Callback | (WordsOptions & CallbackOptions)
): void;
/**
* Diffs two blocks of text, comparing line by line.
*
* @returns A list of change objects.
*/
export function diffLines(oldStr: string, newStr: string, options?: LinesOptions): Change[];
export function diffLines(
oldStr: string,
newStr: string,
options: Callback | (LinesOptions & CallbackOptions)
): void;
/**
* Diffs two blocks of text, comparing line by line, ignoring leading and trailing whitespace.
*
* @returns A list of change objects.
*/
export function diffTrimmedLines(oldStr: string, newStr: string, options?: LinesOptions): Change[];
export function diffTrimmedLines(
oldStr: string,
newStr: string,
options: Callback | (LinesOptions & CallbackOptions)
): void;
/**
* Diffs two blocks of text, comparing sentence by sentence.
*
* @returns A list of change objects.
*/
export function diffSentences(oldStr: string, newStr: string, options?: BaseOptions): Change[];
export function diffSentences(
oldStr: string,
newStr: string,
options: Callback | (BaseOptions & CallbackOptions)
): void;
/**
* Diffs two blocks of text, comparing CSS tokens.
*
* @returns A list of change objects.
*/
export function diffCss(oldStr: string, newStr: string, options?: BaseOptions): Change[];
export function diffCss(
oldStr: string,
newStr: string,
options: Callback | (BaseOptions & CallbackOptions)
): void;
/**
* Diffs two JSON objects, comparing the fields defined on each. The order of fields, etc does not matter
* in this comparison.
*
* @returns A list of change objects.
*/
export function diffJson(
oldObj: string | object,
newObj: string | object,
options?: JsonOptions
): Change[];
export function diffJson(
oldObj: string | object,
newObj: string | object,
options: Callback | (JsonOptions & CallbackOptions)
): void;
/**
* Diffs two arrays, comparing each item for strict equality (`===`).
*
* @returns A list of change objects.
*/
export function diffArrays<TOld, TNew>(
oldArr: TOld[],
newArr: TNew[],
options?: ArrayOptions<TOld, TNew>
): Array<ArrayChange<TOld | TNew>>;
/**
* Creates a unified diff patch.
*
* @param oldFileName String to be output in the filename section of the patch for the removals.
* @param newFileName String to be output in the filename section of the patch for the additions.
* @param oldStr Original string value.
* @param newStr New string value.
* @param oldHeader Additional information to include in the old file header.
* @param newHeader Additional information to include in the new file header.
*/
export function createTwoFilesPatch(
oldFileName: string,
newFileName: string,
oldStr: string,
newStr: string,
oldHeader?: string,
newHeader?: string,
options?: PatchOptions
): string;
/**
* Creates a unified diff patch.
* Just like `createTwoFilesPatch()`, but with `oldFileName` being equal to `newFileName`.
*
* @param fileName String to be output in the filename section.
* @param oldStr Original string value.
* @param newStr New string value.
* @param oldHeader Additional information to include in the old file header.
* @param newHeader Additional information to include in the new file header.
*/
export function createPatch(
fileName: string,
oldStr: string,
newStr: string,
oldHeader?: string,
newHeader?: string,
options?: PatchOptions
): string;
/**
* This method is similar to `createTwoFilesPatch()`, but returns a data structure suitable for further processing.
* Parameters are the same as `createTwoFilesPatch()`.
*
* @param oldFileName String to be output in the `oldFileName` hunk property.
* @param newFileName String to be output in the `newFileName` hunk property.
* @param oldStr Original string value.
* @param newStr New string value.
* @param oldHeader Additional information to include in the `oldHeader` hunk property.
* @param newHeader Additional information to include in the `newHeader` hunk property.
* @returns An object with an array of hunk objects.
*/
export function structuredPatch(
oldFileName: string,
newFileName: string,
oldStr: string,
newStr: string,
oldHeader?: string,
newHeader?: string,
options?: PatchOptions
): ParsedDiff;
/**
* Applies a unified diff patch.
*
* @param patch May be a string diff or the output from the `parsePatch()` or `structuredPatch()` methods.
* @returns A string containing new version of provided data.
*/
export function applyPatch(
source: string,
patch: string | ParsedDiff | [ParsedDiff],
options?: ApplyPatchOptions
): string;
/**
* Applies one or more patches.
* This method will iterate over the contents of the patch and apply to data provided through callbacks.
*
* The general flow for each patch index is:
*
* 1. `options.loadFile(index, callback)` is called. The caller should then load the contents of the file
* and then pass that to the `callback(err, data)` callback. Passing an `err` will terminate further patch execution.
* 2. `options.patched(index, content, callback)` is called once the patch has been applied. `content` will be
* the return value from `applyPatch()`. When it's ready, the caller should call `callback(err)` callback.
* Passing an `err` will terminate further patch execution.
* 3. Once all patches have been applied or an error occurs, the `options.complete(err)` callback is made.
*/
export function applyPatches(patch: string | ParsedDiff[], options: ApplyPatchesOptions): void;
/**
* Parses a patch into structured data.
*
* @returns A JSON object representation of the a patch, suitable for use with the `applyPatch()` method.
*/
export function parsePatch(diffStr: string, options?: { strict?: boolean }): ParsedDiff[];
/**
* Converts a list of changes to a serialized XML format.
*/
export function convertChangesToXML(changes: Change[]): string;
/**
* Converts a list of changes to [DMP](http://code.google.com/p/google-diff-match-patch/wiki/API) format.
*/
export function convertChangesToDMP(changes: Change[]): Array<[1 | 0 | -1, string]>;
export function merge(mine: string, theirs: string, base: string): ParsedDiff;
export function canonicalize(obj: any, stack: any[], replacementStack: any[]): any;
|