JSPM

@philiprehberger/diff-kit

0.1.5
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 47
  • Score
    100M100P100Q83056F
  • License MIT

Object and array diffing with typed patches

Package Exports

  • @philiprehberger/diff-kit

Readme

@philiprehberger/diff-kit

CI npm version Last updated

Object and array diffing with typed patches

Installation

npm install @philiprehberger/diff-kit

Usage

import { diff, applyPatch, revertPatch, hasChanges, summarize } from '@philiprehberger/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 test

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT