• Version 29.7.0
  • Published
  • 78.5 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
          ) => string;

            function diffLinesUnified2

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

              function diffStringsRaw

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

                function diffStringsUnified

                diffStringsUnified: (a: string, b: string, options?: DiffOptions) => 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;
                        compareKeys?: CompareKeys;

                          type DiffOptionsColor

                          type DiffOptionsColor = (arg: string) => string;

                            Package Files (1)

                            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>