Skip to content

Merge ​

@adecore/merge diffs, patches and merges text by line. A three-way merge sorts a base and two versions into blocks that merge by themselves and blocks a person decides, then builds the file from the answers. A diff becomes rows for a view or text for an editor. The package does no I/O and needs no DOM, so it runs in a page and in a backend.

What it does ​

  • Splits text into lines and joins it back with the original line endings.
  • Diffs two arrays of lines, and computes a unified patch with context from two texts.
  • Parses a unified patch, and checks that it fits the two versions it claims to describe.
  • Turns a patch into rows for a unified or split view, with gaps that unfold, and highlights the changed words in a line.
  • Builds editor text for one or two diff panes, and maps a caret back to the file.
  • Sorts a three-way merge into blocks, answers the easy conflicts and builds an editable draft.

What it leaves to the app ​

Every function is synchronous and keeps no state. The app reads the versions, decides who may resolve a conflict, shows the blocks and writes the result. A large comparison blocks its thread, so run it in a worker when the page must stay responsive.

Where to next ​

The package is licensed under FSL-1.1-MIT.

Licenses and third-party notices are listed in each package.