-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllms.txt
More file actions
30 lines (23 loc) · 1.6 KB
/
Copy pathllms.txt
File metadata and controls
30 lines (23 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# text-diff-patch
> Zero-dependency Myers line diff producing unified-diff hunks, with fuzzy patch application, reject reporting, and word-level highlighting.
text-diff-patch computes an O(ND) Myers diff between two texts, formats it as
unified-diff hunks, and can apply those hunks back to a (possibly slightly
shifted) base text — reporting exactly which hunks couldn't be placed rather
than throwing. It also exposes a word-level diff for intra-line highlighting.
Built for agents that generate, store, and re-apply edits against files that
may have drifted since the diff was made.
## API
- `myersDiff(a: string[], b: string[]): DiffOp[]` — `DiffOp = { type: "equal"|"delete"|"insert", value: string }`.
- `toLines(text: string): string[]`
- `buildHunks(ops: DiffOp[], context?: number): Hunk[]` — `Hunk = { oldStart, oldLines, newStart, newLines, lines: string[] }`.
- `createPatch(oldText: string, newText: string, options?: { context?: number; oldFile?: string; newFile?: string }): string`
- `parsePatch(patchText: string): Hunk[]`
- `applyPatch(text: string, patch: string | Hunk[], options?: { fuzz?: number }): { result: string; applied: number; rejects: RejectedHunk[] }` — `RejectedHunk = { hunk: Hunk; reason: string }`.
- `tokenizeWords(line: string): string[]`
- `diffWords(a: string, b: string): DiffOp[]`
- `highlightWordDiff(a: string, b: string, options?: { insertOpen?; insertClose?; deleteOpen?; deleteClose? }): string`
## Install
```bash
npm install @ferrow/text-diff-patch
```
Part of the Ferrow open-source toolkit: https://github.com/FerrowAI/ferrow-toolkit — sponsored by https://ferrow.ai