• Version 27.3.1
  • Published
  • 85.7 kB
  • 4 dependencies
  • MIT license


npm i jest-diff
yarn add jest-diff
pnpm add jest-diff


Display differences clearly so people can review changes confidently.



variable DIFF_DELETE

var DIFF_DELETE: number;
  • 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.'

variable DIFF_EQUAL

var DIFF_EQUAL: number;

    variable DIFF_INSERT

    var DIFF_INSERT: number;


      function diff

      diff: (a: any, b: any, options?: DiffOptions) => string | null;

        function diffLinesRaw

        diffLinesRaw: (aLines: Array<string>, bLines: Array<string>) => Array<Diff>;

          function diffLinesUnified

          diffLinesUnified: (
          aLines: Array<string>,
          bLines: Array<string>,
          options?: DiffOptions | undefined
          ) => string;

            function diffLinesUnified2

            diffLinesUnified2: (
            aLinesDisplay: Array<string>,
            bLinesDisplay: Array<string>,
            aLinesCompare: Array<string>,
            bLinesCompare: Array<string>,
            options?: DiffOptions | undefined
            ) => string;

              function diffStringsRaw

              diffStringsRaw: (a: string, b: string, cleanup: boolean) => Array<Diff>;

                function diffStringsUnified

                diffStringsUnified: (
                a: string,
                b: string,
                options?: DiffOptions | undefined
                ) => string;


                  class Diff

                  class Diff {}
                  • Class representing one diff tuple. Attempts to look like a two-element array (which is what this used to be).

                    Parameter op

                    Operation, one of: DIFF_DELETE, DIFF_INSERT, DIFF_EQUAL.

                    Parameter text

                    Text to be deleted, inserted, or retained.


                  constructor(op: number, text: string);

                    property 0

                    0: number;

                      property 1

                      1: string;

                        Type Aliases

                        type DiffOptions

                        type DiffOptions = {
                        aAnnotation?: string;
                        aColor?: DiffOptionsColor;
                        aIndicator?: string;
                        bAnnotation?: string;
                        bColor?: DiffOptionsColor;
                        bIndicator?: string;
                        changeColor?: DiffOptionsColor;
                        changeLineTrailingSpaceColor?: DiffOptionsColor;
                        commonColor?: DiffOptionsColor;
                        commonIndicator?: string;
                        commonLineTrailingSpaceColor?: DiffOptionsColor;
                        contextLines?: number;
                        emptyFirstOrLastLinePlaceholder?: string;
                        expand?: boolean;
                        includeChangeCounts?: boolean;
                        omitAnnotationLines?: boolean;
                        patchColor?: DiffOptionsColor;

                          type DiffOptionsColor

                          type DiffOptionsColor = (arg: string) => string;
                          • Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

                            This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.

                          Package Files (5)

                          Dependencies (4)

                          Dev Dependencies (2)

                          Peer Dependencies (0)

                          No peer dependencies.


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

                          You may also use to create a custom badge linking to

                          • Markdown
                          • HTML
                            <a href=""><img src="" alt=""></a>