A tiny (304B to 489B) utility to check for deep equality
A tiny (304B to 489B) utility to check for deep equality
A tiny (304B to 489B) utility to check for deep equality
This module supports comparison of all types, including Function, RegExp, Date, Set, Map, TypedArrays, DataView, null, undefined, and NaN values. Complex values (eg, Objects, Arrays, Sets, Maps, etc) are traversed recursively.
Important:
- key order within Objects does not matter
- value order within Arrays does matter
- values within Sets and Maps use value equality
- keys within Maps use value equality
$ npm install --save dequalThere are two "versions" of dequal available:
dequalSize (gzip): 489 bytes
Availability: CommonJS, ES Module, UMD
dequal/lite| IE9+ | Number | String | Date | RegExp | Object | Array | Class | Set | Map | ArrayBuffer | TypedArray | DataView | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
dequal |
:x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
dequal/lite |
:+1: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: |
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); //=> falseReturns: 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 of String, Number, Date, Array, and Object values.complex – like basic, but adds RegExp, Map, Set, and Uint8Array values.Note: Only candidates that pass validation step(s) are listed.
For example,fast-deep-equal/es6handlesSetandMapvalues, but uses referential equality while those listed use value equality.
…MIT © Luke Edwards
No open issues yet, or sync has not completed.