jsdiff

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package jsdiff ports the parts of the npm `diff` package (jsdiff 8.0.4) that Pi calls: diffWords, which Pi's renderDiff uses for intra-line highlighting, and diffLines, behind the edit tool's display diff and patch. Both are Myers' algorithm over tokens; the word diff attaches whitespace to its tokens and runs a whitespace tidy pass.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	Value   string
	Count   int
	Added   bool
	Removed bool
}

Change is one jsdiff change object: a run of text kept, added or removed.

func DiffLines

func DiffLines(oldStr, newStr string) []Change

DiffLines is jsdiff's diffLines(oldStr, newStr) with default options: Myers over line tokens compared exactly.

func DiffWords

func DiffWords(oldStr, newStr string) []Change

DiffWords is jsdiff's diffWords(oldStr, newStr) with default options.

type LineDiff

type LineDiff struct {
	Runs []LineRun
	// contains filtered or unexported fields
}

LineDiff is jsdiff's diffLines(oldStr, newStr) as runs of lines read from the texts on demand.

func DiffLineRuns

func DiffLineRuns(oldStr, newStr string) *LineDiff

DiffLineRuns is jsdiff's diffLines(oldStr, newStr) with default options, without the change values.

func (*LineDiff) Line

func (d *LineDiff) Line(run LineRun, i int) string

Line returns line i of run as jsdiff tokenizes it: with its terminating "\n", which only the last line of a text can lack.

func (*LineDiff) Value

func (d *LineDiff) Value(run LineRun) string

Value is the run's jsdiff change value: its lines joined, a substring of the text they come from.

type LineRun

type LineRun struct {
	Start   int
	Count   int
	Added   bool
	Removed bool
}

LineRun is one part of a line diff: Count lines kept, added or removed. Start is the index of its first line in the text its lines come from: the old text when Removed, the new text otherwise.

Jump to

Keyboard shortcuts

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