@types/diff

  • Version 5.2.0
  • Published
  • 15.3 kB
  • No dependencies
  • MIT license

Install

npm i @types/diff
yarn add @types/diff
pnpm add @types/diff

Overview

TypeScript definitions for diff

Index

Functions

function applyPatch

applyPatch: (
source: string,
patch: string | ParsedDiff | [ParsedDiff],
options?: ApplyPatchOptions
) => string | false;
  • Applies a unified diff patch.

    Parameter patch

    May be a string diff or the output from the parsePatch() or structuredPatch() methods.

    Returns

    A string containing new version of provided data. false when failed

function applyPatches

applyPatches: (
patch: string | ParsedDiff[],
options: ApplyPatchesOptions
) => void;
  • 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.

function canonicalize

canonicalize: (obj: any, stack: any[], replacementStack: any[]) => any;

    function convertChangesToDMP

    convertChangesToDMP: (changes: Change[]) => Array<[1 | 0 | -1, string]>;
    • Converts a list of changes to [DMP](http://code.google.com/p/google-diff-match-patch/wiki/API) format.

    function convertChangesToXML

    convertChangesToXML: (changes: Change[]) => string;
    • Converts a list of changes to a serialized XML format.

    function createPatch

    createPatch: (
    fileName: 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.

      Parameter fileName

      String to be output in the filename section.

      Parameter oldStr

      Original string value.

      Parameter newStr

      New string value.

      Parameter oldHeader

      Additional information to include in the old file header.

      Parameter newHeader

      Additional information to include in the new file header.

    function createTwoFilesPatch

    createTwoFilesPatch: (
    oldFileName: string,
    newFileName: string,
    oldStr: string,
    newStr: string,
    oldHeader?: string,
    newHeader?: string,
    options?: PatchOptions
    ) => string;
    • Creates a unified diff patch.

      Parameter oldFileName

      String to be output in the filename section of the patch for the removals.

      Parameter newFileName

      String to be output in the filename section of the patch for the additions.

      Parameter oldStr

      Original string value.

      Parameter newStr

      New string value.

      Parameter oldHeader

      Additional information to include in the old file header.

      Parameter newHeader

      Additional information to include in the new file header.

    function diffArrays

    diffArrays: <TOld, TNew>(
    oldArr: TOld[],
    newArr: TNew[],
    options?: ArrayOptions<TOld, TNew>
    ) => Array<ArrayChange<TOld | TNew>>;
    • Diffs two arrays, comparing each item for strict equality (===).

      Returns

      A list of change objects.

    function diffChars

    diffChars: {
    (oldStr: string, newStr: string, options?: BaseOptions): Change[];
    (
    oldStr: string,
    newStr: string,
    options: Callback | (BaseOptions & CallbackOptions)
    ): void;
    };
    • Diffs two blocks of text, comparing character by character.

      Returns

      A list of change objects.

    function diffCss

    diffCss: {
    (oldStr: string, newStr: string, options?: BaseOptions): Change[];
    (
    oldStr: string,
    newStr: string,
    options: Callback | (BaseOptions & CallbackOptions)
    ): void;
    };
    • Diffs two blocks of text, comparing CSS tokens.

      Returns

      A list of change objects.

    function diffJson

    diffJson: {
    (
    oldObj: string | object,
    newObj: string | object,
    options?: JsonOptions
    ): Change[];
    (
    oldObj: string | object,
    newObj: string | object,
    options: Callback | (JsonOptions & 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.

    function diffLines

    diffLines: {
    (oldStr: string, newStr: string, options?: LinesOptions): Change[];
    (
    oldStr: string,
    newStr: string,
    options: Callback | (LinesOptions & CallbackOptions)
    ): void;
    };
    • Diffs two blocks of text, comparing line by line.

      Returns

      A list of change objects.

    function diffSentences

    diffSentences: {
    (oldStr: string, newStr: string, options?: BaseOptions): Change[];
    (
    oldStr: string,
    newStr: string,
    options: Callback | (BaseOptions & CallbackOptions)
    ): void;
    };
    • Diffs two blocks of text, comparing sentence by sentence.

      Returns

      A list of change objects.

    function diffTrimmedLines

    diffTrimmedLines: {
    (oldStr: string, newStr: string, options?: LinesOptions): Change[];
    (
    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.

    function diffWords

    diffWords: {
    (oldStr: string, newStr: string, options?: WordsOptions): Change[];
    (
    oldStr: string,
    newStr: string,
    options: Callback | (WordsOptions & CallbackOptions)
    ): void;
    };
    • Diffs two blocks of text, comparing word by word, ignoring whitespace.

      Returns

      A list of change objects.

    function diffWordsWithSpace

    diffWordsWithSpace: {
    (oldStr: string, newStr: string, options?: WordsOptions): Change[];
    (
    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.

    function merge

    merge: (mine: string, theirs: string, base: string) => ParsedDiff;

      function parsePatch

      parsePatch: (
      diffStr: string,
      options?: { strict?: boolean | undefined }
      ) => ParsedDiff[];
      • Parses a patch into structured data.

        Returns

        A JSON object representation of the a patch, suitable for use with the applyPatch() method.

      function reversePatch

      reversePatch: (patch: ParsedDiff | ParsedDiff[]) => ParsedDiff;
      • Returns a new structured patch which when applied will undo the original patch. patch may be either a single structured patch object (as returned by structuredPatch) or an array of them (as returned by parsePatch).

      function structuredPatch

      structuredPatch: (
      oldFileName: string,
      newFileName: string,
      oldStr: string,
      newStr: string,
      oldHeader?: string,
      newHeader?: string,
      options?: PatchOptions
      ) => ParsedDiff;
      • This method is similar to createTwoFilesPatch(), but returns a data structure suitable for further processing. Parameters are the same as createTwoFilesPatch().

        Parameter oldFileName

        String to be output in the oldFileName hunk property.

        Parameter newFileName

        String to be output in the newFileName hunk property.

        Parameter oldStr

        Original string value.

        Parameter newStr

        New string value.

        Parameter oldHeader

        Additional information to include in the oldHeader hunk property.

        Parameter newHeader

        Additional information to include in the newHeader hunk property.

        Returns

        An object with an array of hunk objects.

      Classes

      class Diff

      class Diff {}

        method castInput

        castInput: (value: any) => any;

          method diff

          diff: (
          oldString: string,
          newString: string,
          options?: Callback | (ArrayOptions<any, any> & Partial<CallbackOptions>)
          ) => Change[];

            method equals

            equals: (left: any, right: any) => boolean;

              method extractCommon

              extractCommon: (
              basePath: BestPath,
              newString: string,
              oldString: string,
              diagonalPath: number
              ) => number;

                method join

                join: (chars: string[]) => string;

                  method pushComponent

                  pushComponent: (components: Change[], added: boolean, removed: boolean) => void;

                    method removeEmpty

                    removeEmpty: (array: any[]) => any[];

                      method tokenize

                      tokenize: (value: string) => any;

                        Interfaces

                        interface ApplyPatchesOptions

                        interface ApplyPatchesOptions extends ApplyPatchOptions {}

                          method complete

                          complete: (err: any) => void;

                            method loadFile

                            loadFile: (
                            index: ParsedDiff,
                            callback: (err: any, data: string) => void
                            ) => void;

                              method patched

                              patched: (
                              index: ParsedDiff,
                              content: string,
                              callback: (err: any) => void
                              ) => void;

                                interface ApplyPatchOptions

                                interface ApplyPatchOptions {}

                                  property compareLine

                                  compareLine?:
                                  | ((
                                  lineNumber: number,
                                  line: string,
                                  operation: '-' | ' ',
                                  patchContent: string
                                  ) => boolean)
                                  | undefined;
                                  • 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.

                                    strict equality

                                  property fuzzFactor

                                  fuzzFactor?: number | undefined;
                                  • Number of lines that are allowed to differ before rejecting a patch. 0

                                  interface ArrayChange

                                  interface ArrayChange<T> {}

                                    property added

                                    added?: boolean | undefined;

                                      property count

                                      count?: number | undefined;

                                        property removed

                                        removed?: boolean | undefined;

                                          property value

                                          value: T[];

                                            interface ArrayOptions

                                            interface ArrayOptions<TLeft, TRight> extends BaseOptions {}

                                              property comparator

                                              comparator?: ((left: TLeft, right: TRight) => boolean) | undefined;
                                              • Comparator for custom equality checks.

                                              interface BaseOptions

                                              interface BaseOptions {}

                                                property ignoreCase

                                                ignoreCase?: boolean | undefined;
                                                • true to ignore casing difference. false

                                                interface BestPath

                                                interface BestPath {}

                                                  property components

                                                  components: Change[];

                                                    property newPos

                                                    newPos: number;

                                                      interface CallbackOptions

                                                      interface CallbackOptions {}

                                                        property callback

                                                        callback: Callback;
                                                        • Callback to call with the result instead of returning the result directly.

                                                        interface Change

                                                        interface Change {}

                                                          property added

                                                          added?: boolean | undefined;
                                                          • true if the value was inserted into the new string.

                                                          property count

                                                          count?: number | undefined;

                                                            property removed

                                                            removed?: boolean | undefined;
                                                            • true if the value was removed from the old string.

                                                            property value

                                                            value: string;
                                                            • Text content.

                                                            interface Hunk

                                                            interface Hunk {}

                                                              property linedelimiters

                                                              linedelimiters?: string[];

                                                                property lines

                                                                lines: string[];

                                                                  property newLines

                                                                  newLines: number;

                                                                    property newStart

                                                                    newStart: number;

                                                                      property oldLines

                                                                      oldLines: number;

                                                                        property oldStart

                                                                        oldStart: number;

                                                                          interface JsonOptions

                                                                          interface JsonOptions extends LinesOptions {}

                                                                            property stringifyReplacer

                                                                            stringifyReplacer?: ((key: string, value: any) => any) | undefined;
                                                                            • Replacer used to stringify the properties of the passed objects.

                                                                            property undefinedReplacement

                                                                            undefinedReplacement?: 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. undefined

                                                                            interface LinesOptions

                                                                            interface LinesOptions extends BaseOptions {}

                                                                              property ignoreWhitespace

                                                                              ignoreWhitespace?: boolean | undefined;
                                                                              • true to ignore leading and trailing whitespace. This is the same as diffTrimmedLines().

                                                                              property newlineIsToken

                                                                              newlineIsToken?: boolean | undefined;
                                                                              • 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.

                                                                              interface ParsedDiff

                                                                              interface ParsedDiff {}

                                                                                property hunks

                                                                                hunks: Hunk[];

                                                                                  property index

                                                                                  index?: string | undefined;

                                                                                    property newFileName

                                                                                    newFileName?: string | undefined;

                                                                                      property newHeader

                                                                                      newHeader?: string | undefined;

                                                                                        property oldFileName

                                                                                        oldFileName?: string | undefined;

                                                                                          property oldHeader

                                                                                          oldHeader?: string | undefined;

                                                                                            interface PatchOptions

                                                                                            interface PatchOptions extends LinesOptions {}

                                                                                              property context

                                                                                              context?: number | undefined;
                                                                                              • Describes how many lines of context should be included. 4

                                                                                              interface WordsOptions

                                                                                              interface WordsOptions extends BaseOptions {}

                                                                                                property ignoreWhitespace

                                                                                                ignoreWhitespace?: boolean | undefined;
                                                                                                • true to ignore leading and trailing whitespace. This is the same as diffWords().

                                                                                                Type Aliases

                                                                                                type Callback

                                                                                                type Callback = (err: undefined, value?: Change[]) => void;

                                                                                                  Package Files (1)

                                                                                                  Dependencies (0)

                                                                                                  No dependencies.

                                                                                                  Dev Dependencies (0)

                                                                                                  No dev dependencies.

                                                                                                  Peer Dependencies (0)

                                                                                                  No peer dependencies.

                                                                                                  Badge

                                                                                                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/diff.

                                                                                                  • Markdown
                                                                                                    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/diff)
                                                                                                  • HTML
                                                                                                    <a href="https://www.jsdocs.io/package/@types/diff"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>