tools/editDiff
The text work of the edit tool: line endings, fuzzy matching, applying several replacements against one original,
and the two diff renderings of the result (a numbered display diff and a unified patch).
Since v0.0.0
AppliedEdits (interface)
Section titled “AppliedEdits (interface)”Signature
export interface AppliedEdits { readonly baseContent: string readonly newContent: string}Since v0.0.0
DiffPart (interface)
Section titled “DiffPart (interface)”A run of lines that both sides share, or that one side removed or added.
Signature
export interface DiffPart { readonly value: string readonly count: number readonly added: boolean readonly removed: boolean}Since v0.0.0
Edit (interface)
Section titled “Edit (interface)”One replacement.
Signature
export interface Edit { readonly oldText: string readonly newText: string}Since v0.0.0
FuzzyMatchResult (interface)
Section titled “FuzzyMatchResult (interface)”Signature
export interface FuzzyMatchResult { readonly found: boolean readonly index: number readonly matchLength: number /** Whether fuzzy matching was used (false: an exact match). */ readonly usedFuzzyMatch: boolean /** The content the offsets refer to: the original for an exact match, the normalized content for a fuzzy one. */ readonly contentForReplacement: string}Since v0.0.0
applyEditsToNormalizedContent
Section titled “applyEditsToNormalizedContent”Apply one or more replacements to LF-normalized content. Every edit is matched against the same original; when one needs fuzzy matching, all of them match in fuzzy-normalized space and only the touched lines take normalized text.
Signature
declare const applyEditsToNormalizedContent: ( normalizedContent: string, edits: ReadonlyArray<Edit>, path: string) => Effect.Effect<AppliedEdits, CodingToolError>Since v0.0.0
applyReplacementsPreservingUnchangedLines
Section titled “applyReplacementsPreservingUnchangedLines”Apply replacements matched against baseContent (a normalized view of originalContent) to the original: each
replacement widens to the lines it touches, those lines are rewritten from the base, and every other line keeps its
original bytes.
Signature
declare const applyReplacementsPreservingUnchangedLines: ( originalContent: string, baseContent: string, replacements: ReadonlyArray<TextReplacement>) => stringSince v0.0.0
detectLineEnding
Section titled “detectLineEnding”Signature
declare const detectLineEnding: (content: string) => "\r\n" | "\n"Since v0.0.0
diffLines
Section titled “diffLines”Diff two texts by lines.
Signature
declare const diffLines: (oldText: string, newText: string) => Array<DiffPart>Since v0.0.0
fuzzyFindText
Section titled “fuzzyFindText”Find oldText exactly, else in fuzzy-normalized space.
Signature
declare const fuzzyFindText: (content: string, oldText: string) => FuzzyMatchResultSince v0.0.0
generateDiffString
Section titled “generateDiffString”A display diff with line numbers and contextLines of context around each change, and the first changed line of
the new file.
Signature
declare const generateDiffString: ( oldContent: string, newContent: string, contextLines?: number) => { readonly diff: string; readonly firstChangedLine: number | undefined }Since v0.0.0
generateUnifiedPatch
Section titled “generateUnifiedPatch”A standard unified patch with file headers only (--- path, +++ path) and contextLines of context.
Signature
declare const generateUnifiedPatch: ( path: string, oldContent: string, newContent: string, contextLines?: number) => stringSince v0.0.0
normalizeForFuzzyMatch
Section titled “normalizeForFuzzyMatch”Normalize for fuzzy matching: NFKC, trailing whitespace stripped per line, smart quotes, Unicode dashes and special spaces replaced by their ASCII forms.
Signature
declare const normalizeForFuzzyMatch: (text: string) => stringSince v0.0.0
normalizeToLF
Section titled “normalizeToLF”Signature
declare const normalizeToLF: (text: string) => stringSince v0.0.0
restoreLineEndings
Section titled “restoreLineEndings”Signature
declare const restoreLineEndings: (text: string, ending: "\r\n" | "\n") => stringSince v0.0.0
stripBom
Section titled “stripBom”Strip a UTF-8 BOM, returning it and the rest.
Signature
declare const stripBom: (content: string) => { readonly bom: string; readonly text: string }Since v0.0.0