diff.ts

Line-based diff utilities using LCS (Longest Common Subsequence).

Declarations
#

6 declarations

view source

diff_lines
#

diff.ts view source

(a: string, b: string): DiffLine[]

Generate a line-based diff between two strings using LCS algorithm.

a

The original/current content.

type string

b

The new/desired content.

type string

returns

DiffLine[]

Array of diff lines with type annotations.

DiffLine
#

diff.ts view source

DiffLine

Line diff result

type

type 'same' | 'add' | 'remove'

line

type string

filter_diff_context
#

diff.ts view source

(diff: DiffLine[], context_lines?: number): DiffLine[]

Filter diff to only include lines within N lines of context around changes.

diff

The full diff lines.

type DiffLine[]

context_lines

Number of context lines to show around changes (default: 3).

type number
default 3

returns

DiffLine[]

Filtered diff with ellipsis markers for skipped regions.

format_diff
#

diff.ts view source

(diff: DiffLine[], current_path: string, desired_path: string, options?: FormatDiffOptions): string

Format a diff for display.

diff

The diff lines to format.

type DiffLine[]

current_path

Path label for "current" content.

type string

desired_path

Path label for "desired" content.

type string

options

Formatting options.

default {}

returns

string

Formatted diff string.

FormatDiffOptions
#

diff.ts view source

FormatDiffOptions

Format options for diff output.

prefix

Prefix for each line (for indentation in plan output).

type string

use_color

Whether to use ANSI colors.

type boolean

max_lines

Maximum number of diff lines to show (0 = unlimited).

type number

generate_diff
#

diff.ts view source

(current: string, desired: string, path: string, options?: FormatDiffOptions): string | null

Generate a formatted diff between two strings.

Combines diff_lines, filter_diff_context, and format_diff for convenience. Returns null if content is binary.

current

Current content.

type string

desired

Desired content.

type string

path

File path for labels.

type string

options

Formatting options.

default {}

returns

string | null

Formatted diff string, or null if binary.

Depends on
#