Code Monkey home page Code Monkey logo

node-deep-equal's Introduction

deep-equal Version Badge

Node's assert.deepEqual() algorithm as a standalone module, that also works in browser environments.

It mirrors the robustness of node's own assert.deepEqual and is robust against later builtin modification.

github actions coverage License Downloads

npm badge

example

var equal = require('deep-equal');
console.dir([
    equal(
        { a : [ 2, 3 ], b : [ 4 ] },
        { a : [ 2, 3 ], b : [ 4 ] }
    ),
    equal(
        { x : 5, y : [6] },
        { x : 5, y : 6 }
    )
]);

methods

var deepEqual = require('deep-equal')

deepEqual(a, b, opts)

Compare objects a and b, returning whether they are equal according to a recursive equality algorithm.

If opts.strict is true, use strict equality (===) to compare leaf nodes. The default is to use coercive equality (==) because that's how assert.deepEqual() works by default.

install

With npm do:

npm install deep-equal

test

With npm do:

npm test

node-deep-equal's People

Contributors

agirorn avatar bloodyowl avatar dougwilson avatar erikvold avatar grahambinns avatar grncdr avatar isaacs avatar jarofghosts avatar khirayama avatar korynunn avatar ljharb avatar timretout avatar vruivo avatar xotic750 avatar yubaoquan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-deep-equal's Issues

explodes if Object deep frozen: Object.keys polyfill modifies global Object.keys

When running in strict mode within a context with deep-frozen primordials, things like Object.keys cannot be modified. This is the situation when running in Secure EcmaScript (SES) containers

in lib/keys.js

exports = module.exports = typeof Object.keys === 'function'
  ? Object.keys : shim;

exports.shim = shim;
function shim (obj) {
  var keys = [];
  for (var key in obj) keys.push(key);
  return keys;
}

if Obect.keys is present, it will have shim appended to it. if Object.keys is frozen, this will throw an Error.

node -p "'use strict'; Object.freeze(Object.keys); Object.keys.shim = () => {};"                 
[eval]:1
'use strict'; Object.freeze(Object.keys); Object.keys.shim = () => {};
                                                           ^

TypeError: Cannot add property shim, object is not extensible
    at [eval]:1:60
    at Script.runInThisContext (vm.js:122:20)
    at Object.runInThisContext (vm.js:329:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at evalScript (internal/bootstrap/node.js:589:27)
    at startup (internal/bootstrap/node.js:265:9)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Comparisons don't work as expected with the ES6 / ES2015 Set object

Issue

I'm using the expect package from npm, which uses this package under the hood to check for deep equality. In my eyes, the test below should fail (different values and different references), but it is passing:

it('should fail', () => {
  const actual = new Set('a');
  const expected = new Set('b');
  expect(actual).toEqual(expected);
});

expect-sets

If I did something like this with another collection (like arrays), the test wouldn't pass until 1) the references are the same with assert.equal / , expect.toBe or 2) the values are the same with assert.deepEqual / expect.toEqual

Background

I'm using Babel 5 to use Set. I'm using Node 5, so the Set being used should be native.
Am I doing something wrong, or does this look like a bug in the expect package in the way it handles Sets? I've cross posted a Stack Overflow question as I'm not sure.

I originally posted this on the expect package issues, but they sent me here, since that package uses this package ;)
mjackson/expect#47 (comment)

cc: @mjackson, @rstacruz

Arguments comparison fails

deepEqual(
    [1,2,3],
    (function () { return arguments; })(1,2,3)
);
// true

The arguments comparison will only work if isArguments(actual). If it isn't, then expected is never tested as arguments.

Also, you should remove return deepEqual(a, b, opts); from line 47. All the previous checks will still be valid the second time around and the only part that matters is after this return. It just adds extra processing time.

Also, I would like to see equality checking for Buffers. It is in assert.deepEqual, I think it should be here too.

An in-range update of eslint is breaking the build 🚨

The devDependency eslint was updated from 6.6.0 to 6.7.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build passed (Details).
  • Travis CI - Branch: The build canceled.

Release Notes for v6.7.0
  • 312a88f New: Add grouped-accessor-pairs rule (fixes #12277) (#12331) (Milos Djermanovic)
  • 5c68f5f Update: Add 'lexicalBindings' to no-implicit-globals and change messages (#11996) (Milos Djermanovic)
  • 6eaad96 New: Add suggestions API (#12384) (Will Douglas)
  • b336fbe Fix: indent rule with JSX spread props (#12581) (Nathan Woltman)
  • 97c745d Update: Report assignment expression location in no-cond-assign (#12465) (Milos Djermanovic)
  • 0f01f3d Update: Check member expressions with this in operator-assignment (#12495) (Milos Djermanovic)
  • 62c7038 Fix: invalid token checking in computed-property-spacing (fixes #12198) (#12533) (YeonJuan)
  • 4f8a1ee Update: Add enforceForClassMembers option to no-useless-computed-key (#12110) (ark120202)
  • 1a2eb99 New: new rule no-constructor-return (fixes #12481) (#12529) (Pig Fang)
  • ca3b2a6 New: ignorePatterns in config files (refs eslint/rfcs#22) (#12274) (Toru Nagashima)
  • 60204a3 Docs: Added another Textmate 2 bundle. (#12580) (Ryan Fitzer)
  • 62623f9 Fix: preserve whitespace in multiline-comment-style (fixes #12312) (#12316) (Kai Cataldo)
  • 17a8849 New: Add no-dupe-else-if rule (fixes #12469) (#12504) (Milos Djermanovic)
  • 41a78fd Update: improve location for semi and comma-dangle (#12380) (Chiawen Chen)
  • 0a480f8 Docs: Change "Code Conventions" link in pull-requests.md (#12401) (Denis Sikuler)
  • fed20bb Fix: require-await crash on global await (#12571) (Brad Zacher)
  • b8030fc Update: deprecate personal config (fixes #11914, refs eslint/rfcs#32) (#12426) (Toru Nagashima)
  • 40c8c32 Fix: improve report location for object-curly-spacing (#12563) (Milos Djermanovic)
  • 1110045 Fix: ignore marker-only comments in spaced-comment (fixes #12036) (#12558) (Milos Djermanovic)
  • 6503cb8 Update: Fix uglified object align in key-spacing (fixes #11414) (#12472) (YeonJuan)
  • 40791af Docs: clarify ignoreDestructuring option in the camelcase rule (#12553) (Milos Djermanovic)
  • 07d398d Chore: Add GitHub organization to Sponsor button (#12562) (Brandon Mills)
  • a477707 Chore: Format style guide links so they can be clicked (#12189) (Ivan V)
  • 0f7edef Update: add react plugin config for eslint init (#12446) (Ibrahim Rouis)
  • 448ff1e Update: Report '\08' and '\09' in no-octal-escape (fixes #12080) (#12526) (Milos Djermanovic)
  • 45aa6a3 New: Add no-setter-return rule (fixes #12285) (#12346) (Milos Djermanovic)
  • 0afb518 Fix: invalid autofix in function-call-argument-newline (fixes #12454) (#12539) (YeonJuan)
  • 90305e0 Update: Depcrecate isSpaceBetweenTokens() (#12519) (Kai Cataldo)
  • 41b1e43 New: add option for camelcase (fixes #12527) (#12528) (Pig Fang)
  • f49f1e0 Upgrade: upgrade optionator to avoid license issue (fixes #11536) (#12537) (Pig Fang)
  • 0286b57 Docs: Clean up Getting Started Guide (#12544) (Nicholas C. Zakas)
  • 575a98d Chore: Add funding field to package.json (#12543) (Nicholas C. Zakas)
  • 9e29e18 Fix: sourceCode#isSpaceBetweenTokens() checks non-adjacent tokens (#12491) (Kai Cataldo)
  • 5868550 Docs: add notice about function keyword in keyword-spacing (#12524) (Pig Fang)
  • bb556d5 Fix: curly multi reports single lexical declarations (fixes #11908) (#12513) (Milos Djermanovic)
  • ac60621 Fix: unexpected autofix in prefer-const (fixes #12514) (#12521) (YeonJuan)
  • 990065e Update: curly multi-or-nest flagging semis on next line (fixes #12370) (#12378) (cherryblossom000)
  • 084a8a6 Fix: no-cond-assign with always option reports switch case clauses (#12470) (Milos Djermanovic)
  • 7e41355 Update: improve report location for space-infix-ops (#12324) (Chiawen Chen)
  • 94ff921 Update: Add capIsConstructor option to no-invalid-this (fixes #12271) (#12308) (Milos Djermanovic)
  • de65de6 New: Add prefer-exponentiation-operator rule (fixes #10482) (#12360) (Milos Djermanovic)
  • c78f4a7 Update: Allow JSX exception in no-inline-comments (fixes #11270) (#12388) (Milos Djermanovic)
  • e17fb90 New: allowAfterThisConstructor for no-underscore-dangle (fixes #11488) (#11489) (sripberger)
  • 287ca56 Build: update CI for Node.js 13 (#12496) (Toru Nagashima)
  • 98e1d50 Upgrade: globals to v12.1.0 (#12296) (Tony Brix)
  • 8ac71a3 Sponsors: Sync README with website (ESLint Jenkins)
  • 4e142ea Docs: Update README team and sponsors (ESLint Jenkins)
Commits

The new version differs by 49 commits.

  • 61848b4 6.7.0
  • 9162db9 Build: changelog update for 6.7.0
  • 312a88f New: Add grouped-accessor-pairs rule (fixes #12277) (#12331)
  • 5c68f5f Update: Add 'lexicalBindings' to no-implicit-globals and change messages (#11996)
  • 6eaad96 New: Add suggestions API (#12384)
  • b336fbe Fix: indent rule with JSX spread props (#12581)
  • 97c745d Update: Report assignment expression location in no-cond-assign (#12465)
  • 0f01f3d Update: Check member expressions with this in operator-assignment (#12495)
  • 62c7038 Fix: invalid token checking in computed-property-spacing (fixes #12198) (#12533)
  • 4f8a1ee Update: Add enforceForClassMembers option to no-useless-computed-key (#12110)
  • 1a2eb99 New: new rule no-constructor-return (fixes #12481) (#12529)
  • ca3b2a6 New: ignorePatterns in config files (refs eslint/rfcs#22) (#12274)
  • 60204a3 Docs: Added another Textmate 2 bundle. (#12580)
  • 62623f9 Fix: preserve whitespace in multiline-comment-style (fixes #12312) (#12316)
  • 17a8849 New: Add no-dupe-else-if rule (fixes #12469) (#12504)

There are 49 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Equivalent objects with NaN values are treated as not equal

Node version: 15.14.0
deep-equal version: 2.0.5

Test:

❯ node
Welcome to Node.js v15.14.0.
Type ".help" for more information.
> const deepEqual = require('deep-equal');
undefined
> deepEqual({ a: 123, b: NaN }, { a: 123, b: NaN })
false
>

I was expecting deep-equal to return true.

Node's assert.deepEqual says the above objects are equal:

> const assert = require('assert');
undefined
> assert.deepEqual({ a: 123, b: NaN }, { a: 123, b: NaN })
undefined

And this NaN unit test seems to assert that it returns true (?)

Is returning false the expected behavior?

ESLint config error

Hi I'm getting some issue with eslint. It has something to do with .eslintrc of this library.

ESLint: 6.2.2.

ESLint couldn't find the config "@ljharb" to extend from. Please check that the name of the config is correct.

The config "@ljharb" was referenced from the config file in "....\packages\...\node_modules\deep-equal\.eslintrc".

Upgrading to 2.0.1 results in 'return' outside of function error

It seems that upgrading to node-deep-equal 2.0.1 results in an error. I'm seeing other posts on this issue within the last few days against other projects, so it's unclear the true origin.

./node_modules/is-map/index.js
SyntaxError .../node_modules/is-map/index.js: 'return' outside of function (12:1)

  10 | 		return false;
  11 | 	};
> 12 | 	return;
     | 	^
  13 | }
  14 |
  15 | var $mapHas = $Map ? Map.prototype.has : null;

DOWNGRADING to deep-equal 1.1.1 resolves the problem in my React (CRA) project.

type comparison

var equal = require('deep-equal');
equal([0, 1, 2, 3], ['0', '1', '2', '3'])

should return false

[Proposal] Compare RegExps as string values

Since dates are compared using getTime() method, why regular expressions can not be compared as their string representations?

const foo = /hellowz/i;
const bar = new RegExp('hellowz', 'i');

foo === bar; // false
foo == bar; // false
foo.toString() === bar.toString(); // true

Having your own equality methods

I'd like to, say, deepEqual jQuery('div') === jQuery('div'). This will fail, of course, because they're both the same objects, but they represent the same things.

Is there a way for deepEqual to use a custom comparator function for objects when its available?

deep equal vs. string equality

yo JSON.stringify() might be a little faster

var timer = process.hrtime()
var deepEqual = require('deep-equal')
console.dir([
    deepEqual(
        { a : [ 2, 3 ], b : [ 4 ] },
        { a : [ 2, 3 ], b : [ 4 ] }
    ),
    deepEqual(
        { x : 5, y : [6] },
        { x : 5, y : 6 }
    )
])
var duration = process.hrtime(timer)
var millis = duration[0] * 1000 + duration[1] / 1000000
console.log(millis)

running this code a few times on my laptop yielded mean average of 14.1853544 ms

each run's actual milliseconds and its node-deep-equal return value went as follows just now:

21:09 $ node bleh.js 
[ true, false ]
13.781762
✔ ~/p/blah 
21:09 $ node bleh.js 
[ true, false ]
13.541187
✔ ~/p/blah 
21:11 $ node bleh.js 
[ true, false ]
14.96483
✔ ~/p/blah 
21:11 $ node bleh.js 
[ true, false ]
14.484085
✔ ~/p/blah 
21:11 $ node bleh.js 
[ true, false ]
14.154908

ok. so about 14 milliseconds. now let's check out some comparative benchmark code:

var timer = process.hrtime()
console.dir([
  JSON.stringify(
    { a : [ 2, 3 ], b : [ 4 ] }
  ) ==  JSON.stringify(
    { a : [ 2, 3 ], b : [ 4 ] }
  ),
  JSON.stringify(
    { x : 5, y : [6] }
  ) ==  JSON.stringify(
    { x : 5, y : 6 }
  )
])
var duration = process.hrtime(timer)
var millis = duration[0] * 1000 + duration[1] / 1000000
console.log(millis)

same return value but mean average drops down to 10.632969 ms

21:21 $ node blah.js
[ true, false ]
10.392282
✔ ~/p/blah 
21:21 $ node blah.js
[ true, false ]
10.412387
✔ ~/p/blah 
21:21 $ node blah.js
[ true, false ]
10.682338
✔ ~/p/blah 
21:21 $ node blah.js
[ true, false ]
11.323075
✔ ~/p/blah 
21:21 $ node blah.js
[ true, false ]
10.354763

benchmark code's stylistic writing of JSON.stringify() takes 100% inspiration from the readme.

i wouldn't normally think to write JSON.stringify() with that type of style but it kinda makes sense here

this could be an isolated case where node-deep-equal's slower performance is largely a result of the module import with file system lookup algorithm running before even second-pass function loading time is taken into account. nonetheless, this shows us that when lighting up a small node process for small object deep equal testing, just using string equality operator == between calls to JSON.stringify() will generally outperform the deep-equal stuff

Significant performance regression since 1.1.0

I've observed very nasty performance regression between v1.0.1 and v1.1.0, causing on average x2 CPU usage in one application, and with localised impact even greater in various situations.

I'll post some benchmarks when I get the chance, but posting this in the meantime to give an early heads up.

deepEqual is not a function

Hi,
I am having this issue using the grid from the React wrapper.
I have installed the deep-equal dependency but without success.

Here the details of the error:

main.js:193120 Uncaught TypeError: deepEqual is not a function
at reconcileConfiguration (main.js:193120)
at Grid.componentWillReceiveProps (main.js:193053)
at main.js:288153
at measureLifeCyclePerf (main.js:287618)
at ReactCompositeComponentWrapper.updateComponent (main.js:288152)
at ReactCompositeComponentWrapper.receiveComponent (main.js:288089)
at Object.receiveComponent (main.js:46769)
at ReactCompositeComponentWrapper._updateRenderedComponent (main.js:288296)
at ReactCompositeComponentWrapper._performComponentUpdate (main.js:288266)
at ReactCompositeComponentWrapper.updateComponent (main.js:288187)

Any clues?

Thanks!

Laura.

Bloated npm distribution

Currently the travis.yml, test and example files/directories are being included in the npm distribution. This is causing a bloated npm distribution.

Fails silently on symbols.

Given an object, and another to compare against, deepEqual does not compare symbols against either object (nor does it throw an error to indicate such is not supported by the module).

For example:
deepEqual({ [symbol]: bob }, { [symbol]: null }) // returns true.

Which in my case caused tests to appear to pass. I've looked downstream, but I feel this is the most relevant repository as this module depends on the object-keys shim and it is not the fault of the shim.

Reduce the size of the npm package by limiting the included files

Looks like the files property (https://docs.npmjs.com/files/package.json#files) is not used in package.json to specify the included files, nor is the .npmignore file (https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package) is being used for blacklisting unwanted files, for the package published to npm.

Would you consider adding either the files property or the .npmignore file, so that the resulting package file would have smaller size?

The current size can be seen when executing the command npm pack (https://docs.npmjs.com/cli/pack).

This issue was create via tawata

Set equality

On Node 6.9:

const deepEqual = require("deep-equal"); // v1.0.1
deepEqual(new Set(['a', 'b', 'c']), new Set(['a', 'b', 'c'])); // true
deepEqual(new Set(['a', 'b', 'X']), new Set(['a', 'b', 'c'])); // true

Two sets should not be equal unless their constituents are the same. (Probably the same issue with Map instances too.)

Incorrect result for ArrayBuffer values

Hello,

If I compare two ArrayBuffer variables, the result is always true. Here is a PoC:

import { default as assert } from "assert";
import deepEqual from "deep-equal";

const buffer1 = new ArrayBuffer(8); // initial value of 0's
const buffer2 = new ArrayBuffer(8); // initial value of 0's

const view1 = new Int8Array(buffer1);
const view2 = new Int8Array(buffer2);

view1.fill(9); // change all values to 9's
//view2.fill(9);

//console.dir(buffer1);
//console.dir(buffer2);

console.log(
  deepEqual(buffer1, buffer2)
);

assert.deepEqual(buffer1, buffer2);
//assert.deepStrictEqual(buffer1, buffer2);

deepEqual() returns true while Node.js built-in assert.deepEqual() fails correctly with the following:

AssertionError [ERR_ASSERTION]: Expected values to be loosely deep-equal:

ArrayBuffer {
  [Uint8Contents]: <09 09 09 09 09 09 09 09>,
  byteLength: 8
}

should loosely deep-equal

ArrayBuffer {
  [Uint8Contents]: <00 00 00 00 00 00 00 00>,
  byteLength: 8
}
    at // ...cut... //
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: ArrayBuffer {
    [Uint8Contents]: <09 09 09 09 09 09 09 09>,
    byteLength: 8
  },
  expected: ArrayBuffer {
    [Uint8Contents]: <00 00 00 00 00 00 00 00>,
    byteLength: 8
  },
  operator: 'deepEqual'
}

One options to fix this would be to test if the value is of type ArrayBuffer, then create a temporary view of it and compare this view. This works correctly with deepEqual(). However, there may be a more generic fix which I'm unaware of.

Sets and Maps are not compared properly

The following does not yield the expected result. The order of the entries should not matter but even when ordered, the result is false.

const de = require('deep-equal')

let a = new Map([[{}, 1], [{}, 2], [{}, 1]])
let b = new Map([[{}, 1], [{}, 2], [{}, 1]])

console.log(de(a, b))
// false

a = new Set([{}, 1, {}, {}, 2])
b = new Set([{}, 1, {}, 2, {}])

console.log(de(a, b))
// false

comparing the `prototype` property isn't useful

I assumed from reading the code that the following test case should pass:

test('differing types', function (t) {
    t.notOk(equal(["a","b"], {0: "a", 1: "b"}));
    t.end();
});

It doesn't (i.e it considers those objects equal), since prototype is generally undefined unless you're comparing constructor functions. I think you mean:

    if (Object.getPrototypeOf(actual) !== Object.getPrototypeOf(expected)) return false;

(or some equivalent where that function is not available)

Option for subset or superset equality.

Provide an option to check if objects have a deep subset/superset relationship, checking equality at each level of the object hierarchy only on the values of those keys that are shared, or only the keys in first object in the subset case, or only the keys in the second object in the superset case.

Compare Maps and Sets

@substack wrote in tape-testing/tape#342:

Once this is merged into core I will release a new major version of deep-equal based on the new algorithm that tape can be updated to support.

As far as I can see, node 8 has a deepEqual that can properly compare Maps and Sets:

node-v8.9.4-linux-x64 $ ./bin/node
> const assert = require('assert')
undefined
> assert.deepEqual(new Set('a'), new Set('a'))
undefined
> assert.deepEqual(new Set('a'), new Set('b'))
AssertionError [ERR_ASSERTION]: Set { 'a' } deepEqual Set { 'b' }
>

I find Sets and Maps very useful and want to use them with t.deepEqual() in tape.

Arrays are equal to Objects

I am fixing a bug where arrays have been accidentally converted to objects:

['test', 'the', 'things'] -> { 0: 'test', 1: 'the', 2: 'things' }

I have written a function that tests if this has happened and converts back to the array form. I want to test that my patch works recursively, so it would be very convenient to use deep-equal.

Unfortunately though:

deepEqual(['test', 'the', 'things'], {
    0: 'test',
    1: 'the', 
    2: 'things'
});
// -> true

Would you accept a patch (perhaps with opts) to allow this to return false?

deep-equal 2.0.1 throws is-weakmap compiler error, 'return' outside of function (12:1)

Related to #78, deep-equal v2.0.1 is now causing a 'return' outside of function (12:1) compiler error from is-weakmap, subsequent fixes to is-map and is-set.

STEPS

yarn create react-app my-app --template typescript
cd my-app
yarn add deep-equal
vi src/index.tsx

# Add lines to index.tsx before render()
    import deepEqual from "deep-equal"; // NEW LINE
    deepEqual({}, {});                  // NEW LINE

yarn build

COMPILER ERROR:

Failed to compile.

./node_modules/is-weakmap/index.js
SyntaxError: .../my-app/node_modules/is-weakmap/index.js: 'return' outside of function (12:1)

  10 | 		return false;
  11 | 	};
> 12 | 	return;
     | 	^
  13 | }
  14 |
  15 | var $mapHas = $WeakMap ? $WeakMap.prototype.has : null;


error Command failed with exit code 1.

possible issues with circular references

I've checked with Node.js 0.12.0, and their assert.deepEqual() is able to compare objects with circular references, without running on forever or hitting stack limits.

var assert = require('assert');
var a = {}, b = {};
a.b = b; b.a = a;
assert.deepEqual(a, b);
// throws assertion

Node.js 0.10.36 throws:

TypeError: Converting circular structure to JSON

This isn't as good as actually performing some comparison, but at least it doesn't loop infinitely or anything.

The same thing in tape v3.5.0 with deep-equal v0.2.2 throws:

RangeError: Maximum call stack size exceeded

This might be more of a tape problem, but it actually throws instead of being caught as a failed assertion.

Would it be possible to at least have this return false in this sort of case?

Cheers. Love your work. :)

Feature request: point discrepancy that caused inequality

Sometimes during debug it is hard to determine which exact property/entry/other in nested objects caused inequality.
Serializing both and comparing manually is not easy as items may be in different order.
Maybe you could provide some execution flag or separate method that instead of bool returns path to discrepancy?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • [Deps] Update Update eslint to v8.57.0
  • [Deps] Update Update eslint to v9
  • [Deps] Update Update nyc to v17
  • [Deps] Update Update semver to v7
  • [Deps] Update Update actions/checkout action to v4
  • [Deps] Update Update codecov/codecov-action action to v4
  • 🔐 Create all pending approval PRs at once 🔐

Detected dependencies

github-actions
.github/workflows/node-assert.yml
  • actions/checkout v2
  • codecov/codecov-action v2
  • actions/checkout v2
  • codecov/codecov-action v2
.github/workflows/node-aught.yml
.github/workflows/node-pretest.yml
.github/workflows/node-tens.yml
.github/workflows/rebase.yml
.github/workflows/require-allow-edits.yml
npm
package.json
  • array-buffer-byte-length ^1.0.0
  • call-bind ^1.0.5
  • es-get-iterator ^1.1.3
  • get-intrinsic ^1.2.2
  • is-arguments ^1.1.1
  • is-array-buffer ^3.0.2
  • is-date-object ^1.0.5
  • is-regex ^1.1.4
  • is-shared-array-buffer ^1.0.2
  • isarray ^2.0.5
  • object-is ^1.1.5
  • object-keys ^1.1.1
  • object.assign ^4.1.5
  • regexp.prototype.flags ^1.5.1
  • side-channel ^1.0.4
  • which-boxed-primitive ^1.0.2
  • which-collection ^1.0.1
  • which-typed-array ^1.1.13
  • @ljharb/eslint-config ^21.1.0
  • aud ^2.0.4
  • auto-changelog ^2.4.0
  • available-typed-arrays ^1.0.5
  • eslint =8.8.0
  • for-each ^0.3.3
  • has-proto ^1.0.1
  • has-symbols ^1.0.3
  • has-typed-arrays ^1.0.1
  • in-publish ^2.0.1
  • npmignore ^0.3.1
  • nyc ^10.3.2
  • object.getownpropertydescriptors ^2.1.7
  • safe-publish-latest ^2.0.0
  • semver ^6.3.1
  • tape ^5.7.4
  • node >= 0.4

  • Check this box to trigger a request for Renovate to run again on this repository

Fails simple array tests on IE < 9

Consider the following tests.

These tests have been added to my fork and you can see them here: https://github.com/Xotic750/node-deep-equal

test('arrays initiated', function (t) {
    var a0 = [
            undefined,
            null,
            -1,
            0,
            1,
            false,
            true,
            undefined,
            '',
            'abc',
            null,
            undefined
        ],
        a1 = [
            undefined,
            null,
            -1,
            0,
            1,
            false,
            true,
            undefined,
            '',
            'abc',
            null,
            undefined
        ];

    t.ok(equal(a0, a1));
    t.end();
});

test('arrays assigned', function (t) {
    var a0 = [
            undefined,
            null,
            -1,
            0,
            1,
            false,
            true,
            undefined,
            '',
            'abc',
            null,
            undefined
        ],
        a1 = [];

    a1[0] = undefined;
    a1[1] = null;
    a1[2] = -1;
    a1[3] = 0;
    a1[4] = 1;
    a1[5] = false;
    a1[6] = true;
    a1[7] = undefined;
    a1[8] = '';
    a1[9] = 'abc';
    a1[10] = null;
    a1[11] = undefined;
    a1.length = 12;

    t.ok(equal(a0, a1));
    t.end();
});

test('arrays push', function (t) {
    var a0 = [
            undefined,
            null,
            -1,
            0,
            1,
            false,
            true,
            undefined,
            '',
            'abc',
            null,
            undefined
        ],
        a1 = [];

    a1.push(undefined);
    a1.push(null);
    a1.push(-1);
    a1.push(0);
    a1.push(1);
    a1.push(false);
    a1.push(true);
    a1.push(undefined);
    a1.push('');
    a1.push('abc');
    a1.push(null);
    a1.push(undefined);
    a1.length = 12;

    t.ok(equal(a0, a1));
    t.end();
});

The first test passes but the the others fail. Why? Because IE<9 creates an index for the undefined entries when initiated, but in the other creations no index is created even though the array length is modified. The effect of this is that the object keys length test fails. So, to avoid this you need to avoid the use of the objecy keys shim. Underscore isEqual works because it takes the more expensive route of traversing each index. This problem affects all libraries that base their deepEqual routine on nodes assert routine (ie, assert, expect, proclaim, TAPE are to name a few)

An in-range update of eslint is breaking the build 🚨

The devDependency eslint was updated from 6.7.1 to 6.7.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for v6.7.2
  • bc435a9 Fix: isSpaceBetweenTokens() recognizes spaces in JSXText (fixes #12614) (#12616) (Toru Nagashima)
  • 4928d51 Fix: don't ignore the entry directory (fixes #12604) (#12607) (Toru Nagashima)
  • b41677a Docs: Clarify suggestion's data in Working with Rules (refs #12606) (#12617) (Milos Djermanovic)
  • ea16de4 Fix: Support tagged template literal generics in no-unexpected-multiline (#11698) (Brad Zacher)
  • fa6415d Sponsors: Sync README with website (ESLint Jenkins)
  • e1e158b Sponsors: Sync README with website (ESLint Jenkins)
Commits

The new version differs by 8 commits.

  • dbbba83 6.7.2
  • bc54d15 Build: changelog update for 6.7.2
  • bc435a9 Fix: isSpaceBetweenTokens() recognizes spaces in JSXText (fixes #12614) (#12616)
  • 4928d51 Fix: don't ignore the entry directory (fixes #12604) (#12607)
  • b41677a Docs: Clarify suggestion's data in Working with Rules (refs #12606) (#12617)
  • ea16de4 Fix: Support tagged template literal generics in no-unexpected-multiline (#11698)
  • fa6415d Sponsors: Sync README with website
  • e1e158b Sponsors: Sync README with website

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

v1.0.1 mutates Object.keys when present

hello/

package content here https://npmfs.com/package/deep-equal/1.0.1/lib/keys.js

I'm a little confused by the history here. maybe git history got screwed up? or some commits were backdated and github does not show them correctly?

file history: https://github.com/inspect-js/node-deep-equal/commits/master/lib/keys.js
commits: https://github.com/inspect-js/node-deep-equal/commits/master

It seems like @ljharb replaced keys.js to use the package on Apr 3, 2013
1.0.1 was commited Aug 30, 2015 (years later) but seems the keys.js replacement is missing when you look at those commits https://github.com/inspect-js/node-deep-equal/commits/59c511f5aeae19e3dd1de054077a789d7302be34

anyways, if you could publish a new version with the keys.js replacement, that would be appreciated. thanks/

Please add copyright statement

Hi,

Although node-deep-equal includes a LICENSE file, there is unfortunately no statement of copyright, which is necessary if it is to be uploaded to Debian.

Kind regards,

Tim

New exports field in package.json get wrong mapping

This package got new field in package.json

  "exports": {
    ".": [
      {
        "default": "./index.js"
      },
      "./index.js"
    ],
    "./package": "./package.json",
    "./package.json": "./package"
  },

However, it doesn't work.

To reproduce the error, go to an empty folder.

npm i deep-equal
node
> require('deep-equal/package.json')
Uncaught Error: Cannot find module 'deep-equal/package.json'
Require stack:
- <repl>
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.resolve (internal/modules/cjs/helpers.js:78:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<repl>' ]
}

The fix:
Change

"./package.json": "./package"

To

"./package.json": "./package.json"

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

eslint failing on transitive deep-equal

node: 12.16.1
npm: 6.14.2
eslint: ^6.8.0

when performing npm install I get the following error:
[!] (plugin eslint) Error: Failed to load config "@ljharb" to extend from.
Referenced from: /node_modules/deep-equal/.eslintrc
node_modules/deep-equal/index.js

Please let me know if you need any more details. We are not directly requiring deep-equal, but I'm not sure which package calls it as a dependency.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Deep equal with sparse arrays

So, sparse arrays are deep equal with underscore:

_.isEqual([,], [undefined]) // true

deepEqual([,], [undefined]) // false

This is because sparse arrays have a different set of reported keys with Object.keys. Any idea which one should be right?

Test and Example included in install

I am not sure why #35 was closed, but it is still an issue. Please do not include test and example in the directories for package.json. They should not be included in the npm distribution.

LICENSE file or in-code license?

I know you say it's covered under MIT license, but the license does say:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

... which, if I understand correctly, means that you need to include the text of the license.

`Buffer()` without a `new` keyword is going to be hard-deprecated soon

Refs: nodejs/node#8169, nodejs/node#7152.

Two options here:

  • Use the new Buffer API — Buffer.alloc()/Buffer.from()/Buffer.allocUnsafe() (requires a shim for v0.10/v0.12 and older v4.x versions prior to v4.5.0).
  • Use new Buffer() for the time being — just add the new keyword everywhere. You should manually check that everything is safe in this case, see the links below for more explanation. That might be hard-deprecated at some later point.

More background:

Quick grep (you should better re-check):

deep-equal-1.0.1.tgz/test/cmp.js:82:    t.ok(equal(Buffer('xyz'), Buffer('xyz')));

The grep above only includes the lines that call Buffer() without the new keyword, if you choose to move to the new API — you should probably also replace new Buffer(…) calls.

Support for ES2015 Map/Set

Can we add support for ES2015 Map/Set objects? Currently (version 1.0.1):

var a = new Map
a.set(0, 'a')
var b = new Map
b.set(0, 'b')
deepEqual(a, b) // true
deepEqual(new Set('a'), new Set('b')) // true

We also need this for mjackson/expect#47

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.