dartdiff
Pure Dart text differencing and unified patching inspired by jsdiff.
Implemented APIs
diffCharsdiffWordsdiffWordsWithSpacediffLinesdiffTrimmedLinesdiffSentencesdiffCssdiffJsondiffArraysstructuredPatchcreatePatchcreateTwoFilesPatchformatPatchparsePatchapplyPatchapplyPatchesreversePatchunixToWin/winToUnix/isUnix/isWinconvertChangesToDMP/convertChangesToXML
Usage
import 'package:dartdiff/dartdiff.dart';
void main() {
final changes = diffChars('Old Value.', 'New ValueMoreData.');
if (changes != null) {
print(convertChangesToXML(changes));
}
final patch = createPatch('file.txt', 'a\nb\n', 'a\nc\n');
if (patch != null) {
final patched = applyPatch('a\nb\n', patch);
print(patched); // a\nc\n
}
}
Notes
- Diff functions return
nullwhenmaxEditLengthortimeoutaborts computation. applyPatchreturnsnullwhen a patch cannot be applied.- A custom
wordTokenizerhook is available ondiffWordsto customize tokenization.
Upstream jsdiff Test Corpus
dartdiff includes a converted fixture derived from the upstream jsdiff test corpus:
- Fixture:
test/data/upstream_cases.json - Dart replay test:
test/upstream_converted_cases_test.dart - Fixture integrity test:
test/upstream_parity_test.dart
Fixture regeneration utilities are still available under tool/parity/ (Node + jsdiff harness) when you want to refresh against upstream.