|
14 | 14 | npm install deep-diff
|
15 | 15 | ```
|
16 | 16 |
|
17 |
| -## Testing |
18 |
| -Tests are written using [vows](http://vowsjs.org/) & [should.js](https://github.com/visionmedia/should.js/) (you may need to install them). If you've installed in a development environment you can use npm to run the tests. |
| 17 | +## Tests |
19 | 18 |
|
| 19 | +Tests use [mocha](http://visionmedia.github.io/mocha/) and [expect.js](https://github.com/LearnBoost/expect.js/), so if you clone the [github repository](https://github.com/flitbit/json-ptr) you'll need to run: |
| 20 | + |
| 21 | +```bash |
| 22 | +npm install |
20 | 23 | ```
|
21 |
| -npm test deep-diff |
| 24 | + |
| 25 | +... followed by ... |
| 26 | + |
| 27 | +```bash |
| 28 | +npm test |
| 29 | +``` |
| 30 | + |
| 31 | +... or ... |
| 32 | + |
| 33 | +```bash |
| 34 | +mocha -R spec |
22 | 35 | ```
|
23 | 36 |
|
24 |
| -If you intend to run the examples you'll also need [extend](https://github.com/justmoon/node-extend) and [lodash](https://github.com/bestiejs/lodash). |
| 37 | +### Importing |
25 | 38 |
|
26 |
| -## Warning! |
| 39 | +**nodejs** |
| 40 | +```javascript |
| 41 | +var deep = require('deep-diff') |
| 42 | +``` |
27 | 43 |
|
28 |
| -I've only had time to verify its behavior in node.js. If you're working in a browser you're on your own for now. |
| 44 | +**browser** |
| 45 | +```html |
| 46 | +<script src="deep-diff-0.1.2.min.js"></script> |
| 47 | +``` |
| 48 | + |
| 49 | +> In a browser, `deep-diff` defines a global variable `DeepDiff`. If there is a conflict in the global namesapce you can restore the conflicting definition and assign `deep-diff` to another variable like this: `var deep = DeepDiff.noConflict();`. |
29 | 50 |
|
30 | 51 | ## Simple Examples
|
31 | 52 |
|
@@ -54,7 +75,7 @@ var rhs = {
|
54 | 75 | }
|
55 | 76 | };
|
56 | 77 |
|
57 |
| -var differences = diff(lhs, rhs); |
| 78 | +var differences = diff(lhs, rhs); |
58 | 79 | ```
|
59 | 80 | The code snippet above would result in the following structure describing the differences:
|
60 | 81 | ``` javascript
|
@@ -89,7 +110,7 @@ Differences are reported as one or more change records. Change records have the
|
89 | 110 | * `lhs` - the value on the left-hand-side of the comparison (undefined if kind === 'N')
|
90 | 111 | * `rhs` - the value on the right-hand-side of the comparison (undefined if kind === 'D')
|
91 | 112 | * `index` - when kind === 'A', indicates the array index where the change occurred
|
92 |
| -* `item` - when kind === 'A', contains a nested change record indicating the change that occurred at the array index |
| 113 | +* `item` - when kind === 'A', contains a nested change record indicating the change that occurred at the array index |
93 | 114 |
|
94 | 115 | Change records are generated for all structural differences between `origin` and `comparand`. The methods only consider an object's own properties and array elements; those inherited from an object's prototype chain are not considered.
|
95 | 116 |
|
@@ -126,12 +147,13 @@ var rhs = {
|
126 | 147 | observableDiff(lhs, rhs, function (d) {
|
127 | 148 | // Apply all changes except those to the 'name' property...
|
128 | 149 | if (d.path.length !== 1 || d.path.join('.') !== 'name') {
|
129 |
| - applyChange(lhs, rhs, d); |
| 150 | + applyChange(lhs, rhs, d); |
130 | 151 | }
|
131 |
| -}); |
| 152 | +}); |
132 | 153 | ```
|
133 | 154 |
|
134 | 155 | ## API Documentation
|
| 156 | + |
135 | 157 | A standard import of `var diff = require('deep-diff')` is assumed in all of the code examples. The import results in an object having the following public properties:
|
136 | 158 |
|
137 | 159 | * `diff` - a function that calculates the differences between two objects.
|
|
0 commit comments