export class diff_match_patch { /** * Find the differences between two texts. Simplifies the problem by stripping * any common prefix or suffix off the texts before diffing. * @param {string} text1 Old string to be diffed. * @param {string} text2 New string to be diffed. * @param {boolean=} opt_checklines Optional speedup flag. If present and false, * then don't run a line-level diff first to identify the changed areas. * Defaults to true, which does a faster, slightly less optimal diff. * @param {number=} opt_deadline Optional time when the diff should be complete * by. Used internally for recursive calls. Users should set DiffTimeout * instead. * @return {!Array.} Array of diff tuples. */ diff_main(text1: string, text2: string, opt_checklines?: boolean | undefined, opt_deadline?: number | undefined): Array; private diff_compute_; private diff_lineMode_; private diff_bisect_; private diff_bisectSplit_; private diff_linesToChars_; private diff_charsToLines_; /** * Determine the common prefix of two strings. * @param {string} text1 First string. * @param {string} text2 Second string. * @return {number} The number of characters common to the start of each * string. */ diff_commonPrefix(text1: string, text2: string): number; /** * Determine the common suffix of two strings. * @param {string} text1 First string. * @param {string} text2 Second string. * @return {number} The number of characters common to the end of each string. */ diff_commonSuffix(text1: string, text2: string): number; private diff_commonOverlap_; private diff_halfMatch_; /** * Reduce the number of edits by eliminating semantically trivial equalities. * @param {!Array.} diffs Array of diff tuples. */ diff_cleanupSemantic(diffs: Array): void; /** * Look for single edits surrounded on both sides by equalities * which can be shifted sideways to align the edit to a word boundary. * e.g: The cat came. -> The cat came. * @param {!Array.} diffs Array of diff tuples. */ diff_cleanupSemanticLossless(diffs: Array): void; /** * Reduce the number of edits by eliminating operationally trivial equalities. * @param {!Array.} diffs Array of diff tuples. */ diff_cleanupEfficiency(diffs: Array): void; /** * Reorder and merge like edit sections. Merge equalities. * Any edit section can move as long as it doesn't cross an equality. * @param {!Array.} diffs Array of diff tuples. */ diff_cleanupMerge(diffs: Array): void; /** * loc is a location in text1, compute and return the equivalent location in * text2. * e.g. 'The cat' vs 'The big cat', 1->1, 5->8 * @param {!Array.} diffs Array of diff tuples. * @param {number} loc Location within text1. * @return {number} Location within text2. */ diff_xIndex(diffs: Array, loc: number): number; /** * Convert a diff array into a pretty HTML report. * @param {!Array.} diffs Array of diff tuples. * @return {string} HTML representation. */ diff_prettyHtml(diffs: Array): string; /** * Compute and return the source text (all equalities and deletions). * @param {!Array.} diffs Array of diff tuples. * @return {string} Source text. */ diff_text1(diffs: Array): string; /** * Compute and return the destination text (all equalities and insertions). * @param {!Array.} diffs Array of diff tuples. * @return {string} Destination text. */ diff_text2(diffs: Array): string; /** * Compute the Levenshtein distance; the number of inserted, deleted or * substituted characters. * @param {!Array.} diffs Array of diff tuples. * @return {number} Number of changes. */ diff_levenshtein(diffs: Array): number; /** * Crush the diff into an encoded string which describes the operations * required to transform text1 into text2. * E.g. =3\t-2\t+ing -> Keep 3 chars, delete 2 chars, insert 'ing'. * Operations are tab-separated. Inserted text is escaped using %xx notation. * @param {!Array.} diffs Array of diff tuples. * @return {string} Delta text. */ diff_toDelta(diffs: Array): string; /** * Given the original text1, and an encoded string which describes the * operations required to transform text1 into text2, compute the full diff. * @param {string} text1 Source string for the diff. * @param {string} delta Delta text. * @return {!Array.} Array of diff tuples. * @throws {!Error} If invalid input. */ diff_fromDelta(text1: string, delta: string): Array; /** * Locate the best instance of 'pattern' in 'text' near 'loc'. * @param {string} text The text to search. * @param {string} pattern The pattern to search for. * @param {number} loc The location to search around. * @return {number} Best match index or -1. */ match_main(text: string, pattern: string, loc: number): number; private match_bitap_; private match_alphabet_; private patch_addContext_; /** * Compute a list of patches to turn text1 into text2. * Use diffs if provided, otherwise compute it ourselves. * There are four ways to call this function, depending on what data is * available to the caller: * Method 1: * a = text1, b = text2 * Method 2: * a = diffs * Method 3 (optimal): * a = text1, b = diffs * Method 4 (deprecated, use method 3): * a = text1, b = text2, c = diffs * * @param {string|!Array.} a text1 (methods 1,3,4) or * Array of diff tuples for text1 to text2 (method 2). * @param {string|!Array.} opt_b text2 (methods 1,4) or * Array of diff tuples for text1 to text2 (method 3) or undefined (method 2). * @param {string|!Array.} opt_c Array of diff tuples * for text1 to text2 (method 4) or undefined (methods 1,2,3). * @return {!Array.} Array of Patch objects. */ patch_make(a: string | Array, opt_b: string | Array, opt_c: string | Array): Array; /** * Given an array of patches, return another array that is identical. * @param {!Array.} patches Array of Patch objects. * @return {!Array.} Array of Patch objects. */ patch_deepCopy(patches: Array): Array; /** * Merge a set of patches onto the text. Return a patched text, as well * as a list of true/false values indicating which patches were applied. * @param {!Array.} patches Array of Patch objects. * @param {string} text Old text. * @return {!Array.>} Two element Array, containing the * new text and an array of boolean values. */ patch_apply(patches: Array, text: string): Array>; /** * Add some padding on text start and end so that edges can match something. * Intended to be called only from within patch_apply. * @param {!Array.} patches Array of Patch objects. * @return {string} The padding string added to each side. */ patch_addPadding(patches: Array): string; /** * Look through the patches and break up any which are longer than the maximum * limit of the match algorithm. * Intended to be called only from within patch_apply. * @param {!Array.} patches Array of Patch objects. */ patch_splitMax(patches: Array): void; /** * Take a list of patches and return a textual representation. * @param {!Array.} patches Array of Patch objects. * @return {string} Text representation of patches. */ patch_toText(patches: Array): string; /** * Parse a textual representation of patches and return a list of Patch objects. * @param {string} textline Text representation of patches. * @return {!Array.} Array of Patch objects. * @throws {!Error} If invalid input. */ patch_fromText(textline: string): Array; } /** * The data structure representing a diff is an array of tuples: * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']] * which means: delete 'Hello', add 'Goodbye' and keep ' world.' */ export const DIFF_DELETE: -1; export const DIFF_INSERT: 1; export const DIFF_EQUAL: 0;