michael@0: # diffpatcher michael@0: michael@0: [![Build Status](https://secure.travis-ci.org/Gozala/diffpatcher.png)](http://travis-ci.org/Gozala/diffpatcher) michael@0: michael@0: [![Browser support](https://ci.testling.com/Gozala/diffpatcher.png)](http://ci.testling.com/Gozala/diffpatcher) michael@0: michael@0: Diffpatcher is a small library that lets you treat hashes as if they were michael@0: git repositories. michael@0: michael@0: ## diff michael@0: michael@0: Diff function that takes two hashes and returns delta hash. michael@0: michael@0: ```js michael@0: var diff = require("diffpatcher/diff") michael@0: michael@0: diff({ a: { b: 1 }, c: { d: 2 } }, // hash#1 michael@0: { a: { e: 3 }, c: { d: 4 } }) // hash#2 michael@0: michael@0: // => { // delta michael@0: // a: { michael@0: // b: null, // - michael@0: // e: 3 // + michael@0: // }, michael@0: // c: { michael@0: // d: 4 // ± michael@0: // } michael@0: // } michael@0: ``` michael@0: michael@0: As you can see from the example above `delta` makes no real distinction between michael@0: proprety upadate and property addition. Try to think of additions as an update michael@0: from `undefined` to whatever it's being updated to. michael@0: michael@0: ## patch michael@0: michael@0: Patch fuction takes a `hash` and a `delta` and returns a new `hash` which is michael@0: just like orginial but with delta applied to it. Let's apply delta from the michael@0: previous example to the first hash from the same example michael@0: michael@0: michael@0: ```js michael@0: var patch = require("diffpatcher/patch") michael@0: michael@0: patch({ a: { b: 1 }, c: { d: 2 } }, // hash#1 michael@0: { // delta michael@0: a: { michael@0: b: null, // - michael@0: e: 3 // + michael@0: }, michael@0: c: { michael@0: d: 4 // ± michael@0: } michael@0: }) michael@0: michael@0: // => { a: { e: 3 }, c: { d: 4 } } // hash#2 michael@0: ``` michael@0: michael@0: That's about it really, just diffing hashes and applying thes diffs on them. michael@0: michael@0: michael@0: ### rebase michael@0: michael@0: And as Linus mentioned everything in git can be expressed with `rebase`, that michael@0: also pretty much the case for `diffpatcher`. `rebase` takes `target` hash, michael@0: and rebases `parent` onto it with `diff` applied. michael@0: michael@0: ## Install michael@0: michael@0: npm install diffpatcher