# deep-diff [![Build Status](https://travis-ci.org/flitbit/diff.png?branch=master)](https://travis-ci.org/flitbit/diff)
[![NPM](https://nodei.co/npm/deep-diff.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/deep-diff/)
**deep-diff** is a javascript/node.js module providing utility functions for determining the structural differences between objects and includes some utilities for applying differences across objects.
## Features
* Get the structural differences between two objects.
* Observe the structural differences between two objects.
* When structural differences represent change, apply change from one object to another.
* When structural differences represent change, selectively apply change from one object to another.
## ChangeLog
`0.3.8` - 2017-05-03
* reconciled recently introduced difference between `index.es.js` and `index.js`
* improved npm commands for more reliable contributions
* added a few notes to README regarding contributing.
`0.3.7` - 2017-05-01
* fixed issue #98 by merging @sberan's pull request #99 — better handling of property with `undefined` value existing on either operand. Unit tests supplied.
`0.3.6` - 2017-04-25 — Fixed, closed lingering issues:
* fixed #74 — comparing objects with longer cycles
* fixed #70 — was not properly detecting a deletion when a property on the operand (lhs) had a value of `undefined` and was _undefined_ on the comparand (rhs). :o).
* WARNING! [Still broken when importing in Typescript](https://github.com/flitbit/diff/issues/97).
`0.3.5` - 2017-04-23 — Rolled up recent fixes; patches:
* @stevemao — #79, #80: now testing latest version of node4
* @mortonfox — #85: referencing mocha's new home
* @tdebarochez — #90: fixed error when .toString not a function
* @thiamsantos — #92, #93: changed module system for improved es2015 modules. WARNING! [This PR broke importing `deep-diff` in Typescript as reported by @kgentes in #97](https://github.com/flitbit/diff/issues/97)
`0.3.4` - Typescript users, reference this version until #97 is fixed!
`0.3.3` - Thanks @SimenB: enabled npm script for release (alternate to the Makefile). Also linting as part of `npm test`. Thanks @joeldenning: Fixed issue #35; diffs of top level arrays now working.
`0.3.3` - Thanks @SimenB: enabled npm script for release (alternate to the Makefile). Also linting as part of `npm test`. Thanks @joeldenning: Fixed issue #35; diffs of top level arrays now working.
`0.3.2` - Resolves #46; support more robust filters by including `lhs` and `rhs` in the filter callback. By @Orlando80
`0.3.1` - Better type checking by @Drinks, UMD wrapper by @SimenB. Now certifies against nodejs 12 and iojs (Thanks @SimenB).
`0.2.0` - [Fixes Bug #17](https://github.com/flitbit/diff/issues/17), [Fixes Bug #19](https://github.com/flitbit/diff/issues/19), [Enhancement #21](https://github.com/flitbit/diff/issues/21) Applying changes that are properly structured can now be applied as a change (no longer requires typeof Diff) - supports differences being applied after round-trip serialization to JSON format. Prefilter now reports the path of all changes - it was not showing a path for arrays and anything in the structure below (reported by @ravishvt).
*Breaking Change* – The structure of change records for differences below an array element has changed. Array indexes are now reported as numeric elements in the `path` if the changes is merely edited (an `E` kind). Changes of kind `A` (array) are only reported for changes in the terminal array itself and will have a nested `N` (new) item or a nested `D` (deleted) item.
`0.1.7` - [Enhancement #11](https://github.com/flitbit/diff/issues/11) Added the ability to filter properties that should not be analyzed while calculating differences. Makes `deep-diff` more usable with frameworks that attach housekeeping properties to existing objects. AngularJS does this, and the new filter ability should ease working with it.
`0.1.6` - Changed objects within nested arrays can now be applied. They were previously recording the changes appropriately but `applyDiff` would error. Comparison of `NaN` works more sanely - comparison to number shows difference, comparison to another `Nan` does not.
## Installation
```
npm install deep-diff
```
For the browser, you can install with [bower](http://bower.io/):
```
bower install deep-diff
```
## Tests
Tests use [mocha](http://mochajs.org/) 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:
```bash
npm install
```
... followed by ...
```bash
npm test
```
... or ...
```bash
mocha -R spec
```
### Importing
**nodejs**
```javascript
var deep = require('deep-diff')
```
**browser**
```html
<script src="deep-diff-0.3.1.min.js"></script>
```
> Minified, browser release of the current version of the module is under the `releases` folder.
> In a browser, `deep-diff` defines a global variable `DeepDiff`. If there is a conflict in the global namespace you can restore the conflicting definition and assign `deep-diff` to another variable like this: `var deep = DeepDiff.noConflict();`.
## Simple Examples
In order to describe differences, change revolves around an `origin` object. For consistency, the `origin` object is always the operand on the `left-hand-side` of operations. The `comparand`, which may contain changes, is always on the `right-hand-side` of operations.
``` javascript
var diff = require('deep-diff').diff;
var lhs = {
name: 'my object',
description: 'it\'s an object!',
details: {
it: 'has',
an: 'array',
with: ['a', 'few', 'elements']
}
};
var rhs = {
name: 'updated object',
description: 'it\'s an object!',
details: {
it: 'has',
an: 'array',
with: ['a', 'few', 'more', 'elements', { than: 'before' }]
}
};
var differences = diff(lhs, rhs);
```
*up to v 0.1.7* The code snippet above would result in the following structure describing the differences:
``` javascript
// Versions < 0.2.0
[ { kind: 'E',
path: [ 'name' ],
lhs: 'my object',
rhs: 'updated object' },
{ kind: 'A',
path: [ 'details', 'with' ],
index: 2,
item: { kind: 'E', path: [], lhs: 'elements', rhs: 'more' } },
{ kind: 'A',
path: [ 'details', 'with' ],
index: 3,
item: { kind: 'N', rhs: 'elements' } },
{ kind: 'A',
path: [ 'details', 'with' ],
index: 4,
item: { kind: 'N', rhs: { than: 'before' } } } ]
```
*v 0.2.0 and above* The code snippet above would result in the following structure describing the differences:
``` javascript
[ { kind: 'E',
path: [ 'name' ],
lhs: 'my object',
rhs: 'updated object' },
{ kind: 'E',
path: [ 'details', 'with', 2 ],
lhs: 'elements',
rhs: 'more' },
{ kind: 'A',
path: [ 'details', 'with' ],
index: 3,
item: { kind: 'N', rhs: 'elements' } },
{ kind: 'A',
path: [ 'details', 'with' ],
index: 4,
item: { kind: 'N', rhs: { than: 'before' } } } ]
```
### Differences
Differences are reported as one or more change records. Change records have the following structure:
* `kind` - indicates the kind of change; will be one of the following:
* `N` - indicates a newly added property/element
* `D` - indicates a property/element was deleted
* `E` - indicates a property/element was edited
* `A` - indicates a change occurred within an array
* `path` - the property path (from the left-hand-side root)
* `lhs` - the value on the left-hand-side of the comparison (undefined if kind === 'N')
* `rhs` - the value on the right-hand-side of the comparison (undefined if kind === 'D')
* `index` - when kind === 'A', indicates the array index where the change occurred
* `item` - when kind === 'A', contains a nested change record indicating the change that occurred at the array index
Change records are generated for all structural differences between `origin` and `comparand`. The
没有合适的资源?快使用搜索试试~ 我知道了~
appium 1.15.1版本
共2000个文件
js:1635个
md:194个
json:141个
需积分: 0 0 下载量 112 浏览量
2023-08-21
16:10:17
上传
评论
收藏 152.82MB ZIP 举报
温馨提示
appium 1.15.1版本
资源推荐
资源详情
资源评论
收起资源包目录
appium 1.15.1版本 (2000个子文件)
rc-tree.min.css 19KB
rc-tree.css 19KB
index.css 19KB
base.css 5KB
rc-input-number.min.css 2KB
rc-input-number.css 2KB
index.css 2KB
rc-notification.min.css 2KB
rc-notification.css 2KB
index.css 2KB
prettify.css 676B
readable_streambuffer.js.html 12KB
writable_streambuffer.js.html 9KB
index.html 5KB
index.html 3KB
constants.js.html 2KB
streambuffer.js.html 2KB
dist.js 522KB
umd.js 476KB
rc-tree.js 250KB
rc-notification.js 154KB
rc-input-number.js 145KB
simulator-xcode-6.js 137KB
js-yaml.js 106KB
simctl.js 83KB
index.js 78KB
container.js 65KB
rc-tree.min.js 65KB
q.js 63KB
parser.js 55KB
index.es.js 49KB
simulator-xcode-6.js 48KB
node.js 46KB
simulator-xcode-9.js 44KB
ejs.js 42KB
loader.js 42KB
js-yaml.min.js 41KB
wgxpath.install.js 41KB
semver.js 41KB
sbcs.js 40KB
rc-notification.min.js 37KB
settings.js 36KB
rc-input-number.min.js 35KB
lazy-result.js 35KB
utils.js 35KB
stringifier.js 34KB
index.js 34KB
index.js 34KB
regenerate.js 34KB
dom.js 33KB
simctl.js 33KB
tokenize.js 32KB
launcher.js 31KB
runner.js 30KB
react-i18next.js 30KB
react-i18next.js 30KB
react-i18next.js 30KB
map-generator.js 30KB
big.js 29KB
simulator-xcode-8.js 28KB
Tree.js 28KB
index.js 27KB
webdriverio.js 26KB
dumper.js 26KB
Tree.js 26KB
index.js 25KB
_stream_readable.js 25KB
index.js 25KB
ejs.js 25KB
core.js 24KB
seamless-immutable.js 24KB
seamless-immutable.development.js 24KB
css-syntax-error.js 24KB
url.js 23KB
processor.js 22KB
ejs.min.js 20KB
ConfigParser.js 20KB
ReporterStats.js 19KB
cli.js 19KB
TreeNode.js 19KB
x509.js 19KB
sax.js 19KB
postcss.js 19KB
certificate.js 18KB
prettify.js 17KB
TreeNode.js 17KB
mbcs.js 17KB
input.js 17KB
AnimateChild.js 16KB
previous-map.js 16KB
AnimateChild.js 15KB
manifest.js 15KB
simulator-xcode-9.js 15KB
punycode.js 14KB
pkcs8.js 14KB
result.js 14KB
RequestHandler.js 13KB
index.js 13KB
_stream_writable.js 13KB
permissions.js 13KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
吃不胖的猫~
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功