{"id":13061,"library":"deep-equal-ident","title":"Deep Equality with Object Identity Checks","description":"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.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/fkling/deep-equal-ident","tags":["javascript","lodash","equality","deep","chai","testing"],"install":[{"cmd":"npm install deep-equal-ident","lang":"bash","label":"npm"},{"cmd":"yarn add deep-equal-ident","lang":"bash","label":"yarn"},{"cmd":"pnpm add deep-equal-ident","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The core library is CommonJS-only in v1.x. Direct ESM import will result in errors.","wrong":"import { deepEqualIdent } from 'deep-equal-ident';","symbol":"deepEqualIdent","correct":"const deepEqualIdent = require('deep-equal-ident');"},{"note":"The Chai plugin is also CommonJS. Ensure `chai` is also `require`d.","wrong":"import { useDeepEqualIdent } from 'deep-equal-ident/chai';","symbol":"Chai Plugin","correct":"chai.use(require('deep-equal-ident/chai'));"}],"quickstart":{"code":"const deepEqualIdent = require('deep-equal-ident');\nconst chai = require('chai');\nconst expect = chai.expect;\nconst assert = chai.assert;\n\n// Enable deep-equal-ident's chai extensions\nchai.use(require('deep-equal-ident/chai'));\n\n// Basic usage demonstrating identity awareness\nconst a = [1, 2, 3];\nconst b = [1, 2, 3];\n\nconst foo = [a, a]; // foo contains two references to the *same* object 'a'\nconst bar = [a, b]; // bar contains references to two *different* objects 'a' and 'b'\n\nconsole.log('--- Direct comparison ---');\nconsole.log('deepEqualIdent(a, b):', deepEqualIdent(a, b)); // true (values are deep equal)\nconsole.log('deepEqualIdent(foo, bar):', deepEqualIdent(foo, bar)); // false (identities differ)\n\nconst baz = [b, b]; // baz contains two references to the *same* object 'b'\nconsole.log('deepEqualIdent(foo, baz):', deepEqualIdent(foo, baz)); // true (structures and identities are equivalent, just different root objects)\n\n// Usage with Chai.js\nconsole.log('\\n--- Chai.js integration ---');\ntry {\n  expect(foo).to.not.deep.identically.equal(bar);\n  console.log('Chai Expect: foo is NOT identically equal to bar (correct)');\n} catch (e) {\n  console.error('Chai Expect failed unexpectedly for foo vs bar:', e.message);\n}\n\ntry {\n  assert.deepEqualIdent(foo, baz);\n  console.log('Chai Assert: foo is identically equal to baz (correct)');\n} catch (e) {\n  console.error('Chai Assert failed unexpectedly for foo vs baz:', e.message);\n}","lang":"javascript","description":"Demonstrates the core `deepEqualIdent` function, highlighting its identity-aware comparison, and shows integration with the Chai.js assertion framework."},"warnings":[{"fix":"Ensure you understand the distinction of 'identical deep equality' as explained in the documentation. This is its core feature, not a bug.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `require()` syntax for importing in CommonJS environments. For ESM, consider a dynamic import (`import(...)`) or a build step that handles CJS interoperability.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use `const deepEqualIdent = require('deep-equal-ident');` to correctly import the CommonJS module.","cause":"Attempting to use `import { deepEqualIdent } from 'deep-equal-ident';` in a CommonJS context, or `require('deep-equal-ident').default`.","error":"TypeError: deepEqualIdent is not a function"},{"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.","cause":"Using `import` syntax (e.g., `import { deepEqualIdent } from 'deep-equal-ident';`) in a Node.js project configured as CommonJS.","error":"Error: Cannot use import statement outside a module"},{"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.","cause":"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.","error":"AssertionError: expected [ [ 1, 2, 3 ], [ 1, 2, 3 ] ] to not identically equal [ [ 1, 2, 3 ], [ 1, 2, 3 ] ]"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}