open-index/open-npm huggingface dataset:
npm package: @stephen/automerge-patcher
Description: Utility functions to apply and invert patches generated by Automerge document changes.
Latest version: 0.8.0-alpha.6-patchobject

# Automerge Patcher
Utility functions to apply and invert patches generated by [Automerge](https://automerge.org/) document changes.

## Installation
```bash
npm install @onsetsoftware/automerge-patcher
```

## Usage

```typescript
import { patch, unpatch } from '@onsetsoftware/automerge-patcher';
import {from} from "@automerge/automerge";

const doc = from({foo: 'bar'});

let patch;

const doc2 = change(
  doc,
  {
    patchCallback: (p, old) => {
      // capture inverse of each patch for undo
      patch = unpatch(old, p);
    }
  },
  (doc) => {
    doc.foo = 'baz';
  }
);

console.log(patch); // {action: 'put', path: ['foo'], value: 'bar'}
console.log(doc2.foo); // baz

const doc3 = change(doc2, (doc) => {
  // apply the patch to revert the change
  applyPatch(doc, patch);
});

console.log(doc3.foo); // bar


```