flitbit / diff

Javascript utility for calculating deep difference, capturing changes, and applying changes across objects; for nodejs and the browser.
MIT License
3k stars 214 forks source link

Stricter type checking among `object` types #36

Closed drinks closed 9 years ago

drinks commented 9 years ago

Hi there! I've been getting some unexpected results when types change between different flavors of object:

var dd = require('deep-diff');

dd([], {})
// => undefined

dd({}, /surely these are different!/gi)
// => undefined

dd(['a','b','c'], {a:1, b:1, c:1})
// => [ { kind: 'D',
// =>    path: [ 0 ],
// =>    lhs: 'a' },
// =>  { kind: 'D',
// =>    path: [ 1 ],
// =>    lhs: 'b' },
// =>  { kind: 'D',
// =>    path: [ 2 ],
// =>    lhs: 'c' } ]

dd({a:1}, [1])
// => [ { kind: 'D',
// =>     path: [ 'a' ],
// =>     lhs: 1 },
// =>   { kind: 'N',
// =>     path: [ '0' ],
// =>     rhs: 1 } ]

Here's a patch that inspects objects a little more closely and reports type changes such as {} -> [] as kind E.

flitbit commented 9 years ago

Very nice. Thank you for taking the time to supplement the tests.

drinks commented 9 years ago

Absolutely, thanks for the merge!

flitbit commented 9 years ago

Sure thing; It will be a few days before I update the release packages.