function

diff.lines

function lines(
oldText: string,
newText: string,
options?: Options & { maxEditLength: undefined }
): Change<string>[];

Compare two strings line by line. A line includes its


or
\r
.

@returns

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

Bun.diff.lines("a\nb\n", "a\nc\n");
// [
//   { value: "a\n", added: false, removed: false, count: 1 },
//   { value: "b\n", added: false, removed: true, count: 1 },
//   { value: "c\n", added: true, removed: false, count: 1 },
// ]
function lines(
oldText: string,
newText: string,
options?: Options
): undefined | Change<string>[];

Compare two strings line by line. A line includes its


or
\r
.

@returns

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

Bun.diff.lines("a\nb\n", "a\nc\n");
// [
//   { value: "a\n", added: false, removed: false, count: 1 },
//   { value: "b\n", added: false, removed: true, count: 1 },
//   { value: "c\n", added: true, removed: false, count: 1 },
// ]

Referenced types

interface Options

  • maxEditLength?: number

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

interface Change<T = string>

A run of tokens that were kept, removed or added.

  • added: boolean

    The run is only in the new input.

  • count: number

    The number of tokens (lines, words, characters or elements) in value.

  • removed: boolean

    The run is only in the old input.

  • value: T

    The tokens of the run: joined for text, an array for arrays.