function

diff.hunks

function hunks(
oldText: string,
newText: string,
options?: HunksOptions & { maxEditLength: undefined }
): Hunk[];

Compare two strings line by line and group the changes into the hunks of a unified diff.

@returns

The hunks, or undefined if there are more than maxEditLength edits

function hunks(
oldText: string,
newText: string,
options?: HunksOptions
): undefined | Hunk[];

Compare two strings line by line and group the changes into the hunks of a unified diff.

@returns

The hunks, or undefined if there are more than maxEditLength edits

Referenced types

interface HunksOptions

  • context?: number

    The number of unchanged lines before and after each change, like diff -U. An integer from 0, or Infinity for the whole file.

  • maxEditLength?: number

    Return undefined when the diff adds and removes more than this many tokens in total. An integer from 0, or Infinity.

interface Hunk

One @@ section of a unified diff.

  • lines: string[]

    Each line without its


    , after " " (kept), "-" (removed) or "+" (added). "\\ No newline at end of file" follows a line that has no

    .

  • newLines: number

    The number of lines the hunk keeps or adds.

  • newStart: number

    The first line of the hunk in the new text, from 1. If newLines is 0, the line after the hunk.

  • oldLines: number

    The number of lines the hunk keeps or removes.

  • oldStart: number

    The first line of the hunk in the old text, from 1. If oldLines is 0, the line after the hunk.