function

diff.words

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

Compare two strings word by word. A token is a word of Latin letters, digits and _, a run of spaces, a line ending, or any other single character.

@returns

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

function words(
oldText: string,
newText: string,
options?: Options
): undefined | Change<string>[];

Compare two strings word by word. A token is a word of Latin letters, digits and _, a run of spaces, a line ending, or any other single character.

@returns

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

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.