1 | # JSON Diff and Patch
|
2 |
|
3 | Jiff is an implementation of a subset of [JSON Patch RFC6902](https://tools.ietf.org/html/rfc6902), plus a Diff implementation that generates compliant patches.
|
4 |
|
5 | It currently supports JSON Patch `add`, `replace`, and `remove` operations. It *does not* yet support `move`, `copy`, and `test`.
|
6 |
|
7 | ## Get it
|
8 |
|
9 | `npm install --save jiff`
|
10 |
|
11 | `bower install --save jiff`
|
12 |
|
13 | ## API
|
14 |
|
15 | ### diff
|
16 |
|
17 | ```js
|
18 | var patch = jiff.diff(a, b [, hashFunction]);
|
19 | ```
|
20 |
|
21 | Computes and returns a JSON Patch from `a` to `b`: `a` and `b` must be valid JSON objects/arrays/values of the same type. If `patch` is applied to `a`, it will yield `b`.
|
22 |
|
23 | If provided, the optional `hashFunction` will be used to recognize when two objects are the same. If not provided, `JSON.stringify` will be used.
|
24 |
|
25 | ### patch
|
26 |
|
27 | ```js
|
28 | var b = jiff.patch(patch, a);
|
29 | ```
|
30 |
|
31 | Given an rfc6902 JSON Patch containing only `add`, `replace`, and `remove` operations, apply it to `a` and return the patched JSON object/array/value.
|
32 |
|
33 | ### clone
|
34 |
|
35 | ```js
|
36 | var b = jiff.clone(a);
|
37 | ```
|
38 |
|
39 | Creates a deep copy of `a`, which must be a valid JSON object/array/value.
|
40 |
|
41 | ## License
|
42 |
|
43 | MIT |
\ | No newline at end of file |