CmpStr - v3.2.1
    Preparing search index...

    The DiffChecker class provides methods to compare two texts and generate structured diffs, grouped diffs, and unified diff outputs.

    Index

    Constructors

    Properties

    a: string

    Original input texts and options

    b: string
    diffRun: boolean = false

    Flag to indicate if the diff has already been computed

    entries: DiffLine[] = []

    Computed diff entries and groups

    grouped: DiffGroup[] = []
    options: Required<DiffOptions>

    Methods

    • Computes the diff between the two input texts and populates the entries and grouped arrays.

      Returns void

    • Concatenates an array of tokens back into a string, respecting the diff mode.

      Parameters

      • input: string[]

        Array of tokens

      Returns string

      • Concatenated string
    • Groups adjacent changed lines together, including context lines, and calculates group metrics.

      Returns void

    • Returns the unified diff as a plain ASCII string.

      Returns string

      • Unified diff (ASCII)
    • Returns the unified diff as a CLI-colored string.

      Returns string

      • Unified diff (CLI colors)
    • Compares two lines and records their differences at the configured granularity.

      Parameters

      • a: string

        Line from the first text

      • b: string

        Line from the second text

      • line: number

        Line number

      Returns void

    • Calculates the change magnitude string for a group or line.

      Parameters

      • del: number

        Number of deleted characters

      • ins: number

        Number of inserted characters

      • baseLen: number

        Base length for normalization

      Returns string

      • Magnitude string (e.g. "++-")
    • Generates a unified diff output as a string, with optional CLI coloring.

      Parameters

      • cli: boolean

        If true, use CLI colors; otherwise, ASCII markup

      Returns string

      • Unified diff output
    • Finds all minimal diff blocks between two tokenized strings, returning original text and positions.

      Parameters

      • a: string

        Original line (case preserved)

      • A: string

        Original line (possibly lowercased)

      • b: string

        Modified line (case preserved)

      • B: string

        Modified line (possibly lowercased)

      Returns DiffEntry[]

      • Array of diff entries for this line
    • Splits both input texts into arrays of lines and returns them with the maximum line count.

      Returns { linesA: string[]; linesB: string[]; maxLen: number }

    • Tokenizes a string according to the current diff mode (line or word).

      Parameters

      • input: string

        The string to tokenize

      Returns string[]

      • Array of tokens