Registry / serialization / dequal

dequal

JSON →
library2.0.3jsnpmunverified

dequal is a minimalist utility for performing deep equality checks on JavaScript values. Currently at version 2.0.3, it offers a stable and performant solution for comparing various data types, including primitives, objects, arrays, functions, regular expressions, dates, Sets, Maps, TypedArrays, and DataViews. The library is actively maintained, with recent patches addressing TypeScript type conditions and "nodenext" resolver support. A key differentiator is its exceptionally small bundle size (304B to 489B gzipped) and the provision of two modes: the full `dequal` for comprehensive type support and `dequal/lite` for a smaller footprint that omits support for Sets, Maps, ArrayBuffers, TypedArrays, and DataViews, but maintains IE9+ compatibility. It emphasizes value equality for Set and Map contents/keys, while noting that object key order is irrelevant but array element order is significant.

npm install dequal
INSTALL
IMPORT
SIG · DEQUAL
D
dequal
serializationjavascriptv2.0.3
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

dequal
✓ import { dequal } from 'dequal';
✗ import dequal from 'dequal';
Since v2.0.0, 'dequal' is a named export for both ESM and TypeScript. Default imports will fail.
dequal
✓ const { dequal } = require('dequal');
✗ const dequal = require('dequal');
Since v2.0.0, 'dequal' is a named export for CommonJS environments. Requiring the default export will fail.
dequal (lite)
✓ import { dequal } from 'dequal/lite';
✗ import dequal from 'dequal/lite';
The 'dequal/lite' entrypoint also uses a named export. This version has reduced feature support but is smaller.

This quickstart demonstrates various deep equality checks using the main `dequal` function, covering primitive values, objects, arrays, and sets, and illustrating both equal and unequal comparisons. It highlights the library's behavior regarding array order.

import { dequal } from 'dequal'; // Basic equality checks console.log(dequal(1, 1)); //=> true console.log(dequal({}, {})); //=> true console.log(dequal('foo', 'foo')); //=> true console.log(dequal([1, 2, 3], [1, 2, 3])); //=> true console.log(dequal(null, null)); //=> true console.log(dequal(NaN, NaN)); //=> true // Complex object comparison const obj1 = { a: 1, b: [{ c: 2, d: 'foo' }], e: new Set([1, 2]) }; const obj2 = { a: 1, b: [{ c: 2, d: 'foo' }], e: new Set([2, 1]) }; // Set order doesn't matter console.log(dequal(obj1, obj2)); //=> true // Demonstrating inequality console.log(dequal(1, '1')); //=> false console.log(dequal(null, undefined)); //=> false console.log(dequal({ a: 1, b: [2, 3] }, { a: 1, b: [2, 5] })); //=> false console.log(dequal(/foo/i, /bar/g)); //=> false // Array order matters console.log(dequal([1, 2], [2, 1])); //=> false
Debug
Known issues
breakingThe package migrated from a default export to a named export. Code using `import dequal from 'dequal'` or `const dequal = require('dequal')` will break.
fix
Update imports to `import { dequal } from 'dequal'` for ESM/TypeScript or `const { dequal } = require('dequal')` for CommonJS.
affects: >=2.0.0
breakingSupport for Internet Explorer (IE9+) was dropped in the main `dequal` bundle.
fix
If IE9+ compatibility is required, use `dequal/lite` instead. Be aware of its feature limitations for certain complex types.
affects: >=2.0.0
gotchaThe `dequal/lite` entrypoint is a smaller, more performant bundle but lacks support for comparing `Set`, `Map`, `ArrayBuffer`, `TypedArray`s, and `DataView` types.
fix
Always use the main `dequal` import (`import { dequal } from 'dequal'`) when comparing these complex types to ensure correct behavior.
affects: >=2.0.0
gotchaWhile object key order does not affect equality, the order of elements within arrays *does* matter for `dequal` to return true.
fix
If array element order should not matter for your comparison, sort the arrays before passing them to `dequal` or use a different comparison logic.
affects: >=1.0.0
gotchaFor `Set` and `Map` types, `dequal` uses value equality for their contents and keys, respectively. This might behave differently than other deep comparison libraries that sometimes rely on referential equality for these structures.
fix
Ensure this behavior aligns with your expectations when comparing `Set` or `Map` instances. If referential equality is desired, compare the instances directly without `dequal`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: dequal is not a function
Attempting to use `dequal` as a default export in CommonJS after v2.0.0.
fix
Change `const dequal = require('dequal');` to `const { dequal } = require('dequal');`
TypeError: Cannot read properties of undefined (reading 'dequal')
Attempting to use `dequal` as a default export in ESM/TypeScript after v2.0.0.
fix
Change `import dequal from 'dequal';` to `import { dequal } from 'dequal';`
dequal(setA, setB) returns false, but they look identical
Likely comparing `Set` or `Map` types using `dequal/lite`, which does not support these types.
fix
Ensure you are importing the full `dequal` library: `import { dequal } from 'dequal';` not `from 'dequal/lite';`
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
11
Resources
dequal — npm install dequal · libregistry