Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 # diffpatcher
3 [](http://travis-ci.org/Gozala/diffpatcher)
5 [](http://ci.testling.com/Gozala/diffpatcher)
7 Diffpatcher is a small library that lets you treat hashes as if they were
8 git repositories.
10 ## diff
12 Diff function that takes two hashes and returns delta hash.
14 ```js
15 var diff = require("diffpatcher/diff")
17 diff({ a: { b: 1 }, c: { d: 2 } }, // hash#1
18 { a: { e: 3 }, c: { d: 4 } }) // hash#2
20 // => { // delta
21 // a: {
22 // b: null, // -
23 // e: 3 // +
24 // },
25 // c: {
26 // d: 4 // ±
27 // }
28 // }
29 ```
31 As you can see from the example above `delta` makes no real distinction between
32 proprety upadate and property addition. Try to think of additions as an update
33 from `undefined` to whatever it's being updated to.
35 ## patch
37 Patch fuction takes a `hash` and a `delta` and returns a new `hash` which is
38 just like orginial but with delta applied to it. Let's apply delta from the
39 previous example to the first hash from the same example
42 ```js
43 var patch = require("diffpatcher/patch")
45 patch({ a: { b: 1 }, c: { d: 2 } }, // hash#1
46 { // delta
47 a: {
48 b: null, // -
49 e: 3 // +
50 },
51 c: {
52 d: 4 // ±
53 }
54 })
56 // => { a: { e: 3 }, c: { d: 4 } } // hash#2
57 ```
59 That's about it really, just diffing hashes and applying thes diffs on them.
62 ### rebase
64 And as Linus mentioned everything in git can be expressed with `rebase`, that
65 also pretty much the case for `diffpatcher`. `rebase` takes `target` hash,
66 and rebases `parent` onto it with `diff` applied.
68 ## Install
70 npm install diffpatcher