A tiny (304B to 489B) utility to check for deep equality
This module supports comparison of all types, including Function
, RegExp
, Date
, null
, undefined
, and NaN
values. Objects and Arrays are traversed recursively.
Please note that key order within Objects does not matter.
However, the value order within Arrays does matter.
This module exposes three module definitions:
- CommonJS:
dist/dequal.js
- ESModule:
dist/dequal.mjs
- UMD:
dist/dequal.min.js
$ npm install --save dequal
There are two "versions" of dequal
available:
Size (gzip): 489 bytes
Availability: CommonJS, ES Module, UMD
IE9+ | Number | String | Date | RegExp | Object | Array | Class | Set | Map | ArrayBuffer | TypedArray | DataView | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
dequal |
❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
dequal/lite |
👍 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
Note: Table scrolls horizontally!
import dequal from 'dequal';
dequal(1, 1); //=> true
dequal({}, {}); //=> true
dequal('foo', 'foo'); //=> true
dequal([1, 2, 3], [1, 2, 3]); //=> true
dequal(dequal, dequal); //=> true
dequal(/foo/, /foo/); //=> true
dequal(null, null); //=> true
dequal(NaN, NaN); //=> true
dequal([], []); //=> true
dequal(
[{ a:1 }, [{ b:{ c:[1] } }]],
[{ a:1 }, [{ b:{ c:[1] } }]]
); //=> true
dequal(1, '1'); //=> false
dequal(null, undefined); //=> false
dequal({ a:1, b:[2,3] }, { a:1, b:[2,5] }); //=> false
dequal(/foo/i, /bar/g); //=> false
Returns: Boolean
Both foo
and bar
can be of any type.
A Boolean
is returned indicating if the two were deeply equal.
Running Node v10.13.0
The benchmarks can be found in the /bench
directory. They are separated into two categories:
basic
– compares an object comprised ofString
,Number
,Date
,Array
, andObject
values.complex
– likebasic
, but addsRegExp
,Map
,Set
, andUint8Array
values.
Note: Only candidates that pass validation step(s) are listed.
For example,fast-deep-equal/es6
handlesSet
andMap
values, but uses referential equality while those listed use value equality.
Load times:
assert 0.109ms
util 0.006ms
fast-deep-equal 0.479ms
lodash/isequal 22.826ms
nano-equal 0.417ms
dequal 0.396ms
dequal/lite 0.264ms
Benchmark :: basic
assert.deepStrictEqual x 325,262 ops/sec ±0.57% (94 runs sampled)
util.isDeepStrictEqual x 318,812 ops/sec ±0.87% (94 runs sampled)
fast-deep-equal x 1,332,393 ops/sec ±0.36% (93 runs sampled)
lodash.isEqual x 269,129 ops/sec ±0.59% (95 runs sampled)
nano-equal x 1,122,053 ops/sec ±0.36% (96 runs sampled)
dequal/lite x 1,700,972 ops/sec ±0.31% (94 runs sampled)
dequal x 1,698,972 ops/sec ±0.63% (97 runs sampled)
Benchmark :: complex
assert.deepStrictEqual x 124,518 ops/sec ±0.64% (96 runs sampled)
util.isDeepStrictEqual x 125,113 ops/sec ±0.24% (96 runs sampled)
lodash.isEqual x 58,677 ops/sec ±0.49% (96 runs sampled)
dequal x 345,386 ops/sec ±0.27% (96 runs sampled)
MIT © Luke Edwards