@philiprehberger/diff-kit
v0.1.3
Published
Object and array diffing with typed patches
Readme
@philiprehberger/ts-diff-kit
Object and array diffing with typed patches.
Installation
npm install @philiprehberger/ts-diff-kitUsage
import { diff, applyPatch, revertPatch, hasChanges, summarize } from '@philiprehberger/ts-diff-kit';
const changes = diff(oldUser, newUser);
// [{ type: 'update', path: ['age'], oldValue: 30, newValue: 31 }]
const restored = revertPatch(newUser, changes); // equals oldUser
summarize(changes); // "Updated age"
hasChanges(a, b); // true (fast)API
| Function | Description |
|----------|-------------|
| diff(old, new, options?) | Deep diff two objects |
| applyPatch(obj, changes) | Apply changes to an object |
| revertPatch(obj, changes) | Undo changes |
| hasChanges(old, new) | Quick boolean check |
| summarize(changes) | Human-readable summary |
| diffArrays(old, new, { key }) | Diff arrays by identity key |
Development
npm install
npm run build
npm testLicense
MIT
