GuardsChecker Functions
Check Deep Equality
Performs deep comparison between two values (arrays, objects, and primitives) to determine if they are structurally and value-wise equal.
isDeepEqual
Performs a deep comparison between two values (arrays, objects, and primitives) to determine if they are structurally and value-wise equal.
Info
This function is one of the foundational utilities, used internally throughout the package to compare arrays, objects, or any deeply nested structures.
Import
import { isDeepEqual } from 'toolbox-x';
// or
import { isDeepEqual } from 'toolbox-x/guards';Signature
isDeepEqual(a: unknown, b: unknown): booleanUsage Examples
playground.ts
API Reference
Parameters
| Name | Type | Description |
|---|---|---|
| a | unknown | First value to compare. |
| b | unknown | Second value to compare. |
Returns
trueif the values are deeply equal.falseotherwise.
How it Works
- Strict Equality First: If
aandbare the same reference or primitive value, returnstrueimmediately. - Type & Null Checks: If types differ or either value is null, returns
falseunless both are strictly equal. - Array Handling: Arrays compared recursively, including nested arrays.
- Object Handling: Objects compared recursively, ensuring both keys and values match exactly.
- Shallow/Deep: Works for deeply nested arrays/objects as well as simple values.
Key Features
- Recursive & Robust: Handles arbitrary nesting for arrays and objects.
- Type Safety: Works generically for any consistent types.
- Foundational Utility: This deep comparison utility powers internal checks across many toolbox functions (e.g., deduplication, merging, diffing, and more).
Limitations
- No Cycles Supported: Will stack overflow on circular references.
- No Symbol/Function/Date Support: Only works for plain objects, arrays, and primitives. Special types (functions, Dates, Maps, Sets, Symbols) are not deeply compared.
- No Non-Enumerable or Prototype Chain: Only own keys are compared, prototype chain & non-enumerable properties are ignored.
- No Partial/Object Subset Comparison: Strict equality over all keys and values only.
Notes
- If you compare objects with arrays, types, or keys in different order but same values, equality will follow JavaScript’s structure (order matters in arrays, not in objects).
- For performance sensitive code, avoid using on excessively large or deeply nested structures unless necessary.
- This function is extensively used internally in
toolbox-xfor object/array equality checks.
Recommended Use Cases
- Deduplicating structurally equal objects/arrays.
- Testing and assertion helpers.
- Data merging, diffing, or synchronization.
- Safely comparing complex API payloads or configurations.
Last updated: Sun, Jun 14, 2026 08:37:01PM (UTC)
