dartdiff 1.0.0 copy "dartdiff: ^1.0.0" to clipboard
dartdiff: ^1.0.0 copied to clipboard

Pure Dart port of jsdiff for text diffs, patches, and format conversion.

dartdiff #

Pure Dart text differencing and unified patching inspired by jsdiff.

Implemented APIs #

  • diffChars
  • diffWords
  • diffWordsWithSpace
  • diffLines
  • diffTrimmedLines
  • diffSentences
  • diffCss
  • diffJson
  • diffArrays
  • structuredPatch
  • createPatch
  • createTwoFilesPatch
  • formatPatch
  • parsePatch
  • applyPatch
  • applyPatches
  • reversePatch
  • unixToWin / winToUnix / isUnix / isWin
  • convertChangesToDMP / 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 null when maxEditLength or timeout aborts computation.
  • applyPatch returns null when a patch cannot be applied.
  • A custom wordTokenizer hook is available on diffWords to 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.

0
likes
150
points
256
downloads

Documentation

API reference

Publisher

verified publisherjodoin.me

Weekly Downloads

Pure Dart port of jsdiff for text diffs, patches, and format conversion.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on dartdiff