UNPKG

1.12 kBMarkdownView Raw
1# JSON Diff and Patch
2
3Jiff 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
5It 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
18var patch = jiff.diff(a, b [, hashFunction]);
19```
20
21Computes 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
23If 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
28var b = jiff.patch(patch, a);
29```
30
31Given 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
36var b = jiff.clone(a);
37```
38
39Creates a deep copy of `a`, which must be a valid JSON object/array/value.
40
41## License
42
43MIT
\No newline at end of file