diff

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package diff provides line-based diff computation using the LCS algorithm, unified format output, and JSON structure comparison. It supports configurable context lines around each change hunk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareJSON

func CompareJSON(v1, v2 any) []string

CompareJSON compares two parsed JSON values and returns a list of human-readable differences.

func CompareJSONBytes

func CompareJSONBytes(data1, data2 []byte) ([]string, error)

CompareJSONBytes parses and compares two JSON byte slices.

func FormatUnified

func FormatUnified(w io.Writer, file1, file2 string, hunks []Hunk)

FormatUnified formats hunks as a unified diff string.

func TruncateOrPad

func TruncateOrPad(s string, width int) string

TruncateOrPad truncates a string to width or pads it with spaces.

Types

type Hunk

type Hunk struct {
	Start1 int
	Count1 int
	Start2 int
	Count2 int
	Lines  []Line
}

Hunk represents a contiguous block of changes.

func ComputeDiff

func ComputeDiff(lines1, lines2 []string, opts ...Option) []Hunk

ComputeDiff computes the diff between two slices of strings using an LCS algorithm. Returns hunks describing the changes.

type Line

type Line struct {
	Type    rune // ' ' for context, '-' for removed, '+' for added
	Content string
}

Line represents a single line in a diff.

type Option

type Option func(*Options)

Option is a functional option for diff operations.

func WithContext

func WithContext(n int) Option

WithContext sets the number of context lines around changes.

type Options

type Options struct {
	Context int // Lines of context (default 3)
}

Options configures diff computation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL