Registry / testing / deep-equal-ident

deep-equal-ident

JSON →
library1.1.1jsnpmunverified

deep-equal-ident is a JavaScript utility function that performs a deep comparison between two values, extending the functionality typically found in libraries like Lodash's `isEqual`. While most deep equality checks, including Lodash's, only compare the *values* of nested objects, `deep-equal-ident` critically tracks and compares the *identity* of nested objects and arrays. This means that two structures like `[[a, a]]` and `[[a, b]]` will be considered unequal by `deep-equal-ident` even if `a` and `b` are themselves deeply value-equal, because the former contains two references to the *same* object `a`, while the latter contains references to two *different* objects (`a` and `b`). This distinction is crucial for preserving structural integrity, mirroring how a robust deep cloning algorithm would behave, ensuring that if two structures are deemed equal, they will behave identically under mutation. The current stable version is 1.1.1, with recent updates focused on stability fixes. It is primarily intended for unit testing scenarios, offering direct integration with the Chai.js assertion framework for both `expect` and `assert` interfaces.

npm install deep-equal-ident
INSTALL
IMPORT
SIG · DEEP-EQUAL-IDENT
D
deep-equal-ident
testingjavascriptv1.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

deepEqualIdent
const deepEqualIdent = require('deep-equal-ident');
import { deepEqualIdent } from 'deep-equal-ident';
The core library is CommonJS-only in v1.x. Direct ESM import will result in errors.
Chai Plugin
chai.use(require('deep-equal-ident/chai'));
import { useDeepEqualIdent } from 'deep-equal-ident/chai';
The Chai plugin is also CommonJS. Ensure `chai` is also `require`d.

Demonstrates the core `deepEqualIdent` function, highlighting its identity-aware comparison, and shows integration with the Chai.js assertion framework.

const deepEqualIdent = require('deep-equal-ident'); const chai = require('chai'); const expect = chai.expect; const assert = chai.assert; // Enable deep-equal-ident's chai extensions chai.use(require('deep-equal-ident/chai')); // Basic usage demonstrating identity awareness const a = [1, 2, 3]; const b = [1, 2, 3]; const foo = [a, a]; // foo contains two references to the *same* object 'a' const bar = [a, b]; // bar contains references to two *different* objects 'a' and 'b' console.log('--- Direct comparison ---'); console.log('deepEqualIdent(a, b):', deepEqualIdent(a, b)); // true (values are deep equal) console.log('deepEqualIdent(foo, bar):', deepEqualIdent(foo, bar)); // false (identities differ) const baz = [b, b]; // baz contains two references to the *same* object 'b' console.log('deepEqualIdent(foo, baz):', deepEqualIdent(foo, baz)); // true (structures and identities are equivalent, just different root objects) // Usage with Chai.js console.log('\n--- Chai.js integration ---'); try { expect(foo).to.not.deep.identically.equal(bar); console.log('Chai Expect: foo is NOT identically equal to bar (correct)'); } catch (e) { console.error('Chai Expect failed unexpectedly for foo vs bar:', e.message); } try { assert.deepEqualIdent(foo, baz); console.log('Chai Assert: foo is identically equal to baz (correct)'); } catch (e) { console.error('Chai Assert failed unexpectedly for foo vs baz:', e.message); }
Debug
Known issues
gotchaThis library's behavior for deep equality differs from standard implementations like Lodash's `_.isEqual` by tracking object identity. Structures like `[[obj, obj]]` and `[[obj1, obj2]]` (where `obj1` and `obj2` are value-equal but distinct objects) will be considered unequal, which might surprise users expecting only value comparison.
fix
Ensure you understand the distinction of 'identical deep equality' as explained in the documentation. This is its core feature, not a bug.
affects: >=1.0.0
gotchaThe package is primarily distributed as CommonJS. Attempting to use `import` statements directly in an ESM project without proper configuration (e.g., via a bundler or specific Node.js settings for interoperability) will lead to runtime errors.
fix
Use `require()` syntax for importing in CommonJS environments. For ESM, consider a dynamic import (`import(...)`) or a build step that handles CJS interoperability.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: deepEqualIdent is not a function
Attempting to use `import { deepEqualIdent } from 'deep-equal-ident';` in a CommonJS context, or `require('deep-equal-ident').default`.
fix
Use `const deepEqualIdent = require('deep-equal-ident');` to correctly import the CommonJS module.
Error: Cannot use import statement outside a module
Using `import` syntax (e.g., `import { deepEqualIdent } from 'deep-equal-ident';`) in a Node.js project configured as CommonJS.
fix
If your project is CommonJS, use `const deepEqualIdent = require('deep-equal-ident');`. If your project is ESM, you might need to use dynamic `import()` or configure your bundler/runtime for CJS interoperability.
AssertionError: expected [ [ 1, 2, 3 ], [ 1, 2, 3 ] ] to not identically equal [ [ 1, 2, 3 ], [ 1, 2, 3 ] ]
This error occurs when `deep-equal-ident` (or its Chai integration) correctly identifies that two seemingly value-equal structures have different internal object identities, but the developer expected them to be identically equal based only on their values.
fix
Re-evaluate the data structures being compared. If you intend for two distinct objects that happen to have the same values to be considered equal, `deep-equal-ident` is not the right tool; use a standard deep equality library like `lodash.isEqual` instead. If object identity *is* important, this assertion indicates a real structural difference.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Resources
deep-equal-ident — npm install deep-equal-ident · libregistry