Debian Codegraph @

node/dequal/readme.md

raw
1 # dequal [![CI](https://github.com/lukeed/dequal/workflows/CI/badge.svg)](https://github.com/lukeed/dequal/actions)
2
3 > A tiny (304B to 489B) utility to check for deep equality
4
5 This module supports comparison of all types, including `Function`, `RegExp`, `Date`, `Set`, `Map`, `TypedArray`s, `DataView`, `null`, `undefined`, and `NaN` values. Complex values (eg, Objects, Arrays, Sets, Maps, etc) are traversed recursively.
6
7 > **Important:**
8 > * key order **within Objects** does not matter
9 > * value order **within Arrays** _does_ matter
10 > * values **within Sets and Maps** use value equality
11 > * keys **within Maps** use value equality
12
13
14 ## Install
15
16 ```
17 $ npm install --save dequal
18 ```
19
20 ## Modes
21
22 There are two "versions" of `dequal` available:
23
24 #### `dequal`
25 > **Size (gzip):** 489 bytes<br>
26 > **Availability:** [CommonJS](https://unpkg.com/dequal/dist/index.js), [ES Module](https://unpkg.com/dequal/dist/index.mjs), [UMD](https://unpkg.com/dequal/dist/index.min.js)
27
28 #### `dequal/lite`
29 > **Size (gzip):** 304 bytes<br>
30 > **Availability:** [CommonJS](https://unpkg.com/dequal/lite/index.js), [ES Module](https://unpkg.com/dequal/lite/index.mjs)
31
32 | | IE9+ | Number | String | Date | RegExp | Object | Array | Class | Set | Map | ArrayBuffer | [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#TypedArray_objects) | [DataView](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) |
33 |-|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
34 | `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: |
35 | `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: |
36
37 > <sup>**Note:** Table scrolls horizontally!</sup>
38
39 ## Usage
40
41 ```js
42 import { dequal } from 'dequal';
43
44 dequal(1, 1); //=> true
45 dequal({}, {}); //=> true
46 dequal('foo', 'foo'); //=> true
47 dequal([1, 2, 3], [1, 2, 3]); //=> true
48 dequal(dequal, dequal); //=> true
49 dequal(/foo/, /foo/); //=> true
50 dequal(null, null); //=> true
51 dequal(NaN, NaN); //=> true
52 dequal([], []); //=> true
53 dequal(
54 [{ a:1 }, [{ b:{ c:[1] } }]],
55 [{ a:1 }, [{ b:{ c:[1] } }]]
56 ); //=> true
57
58 dequal(1, '1'); //=> false
59 dequal(null, undefined); //=> false
60 dequal({ a:1, b:[2,3] }, { a:1, b:[2,5] }); //=> false
61 dequal(/foo/i, /bar/g); //=> false
62 ```
63
64 ## API
65
66 ### dequal(foo, bar)
67 Returns: `Boolean`
68
69 Both `foo` and `bar` can be of any type.<br>
70 A `Boolean` is returned indicating if the two were deeply equal.
71
72
73 ## Benchmarks
74
75 > Running Node v10.13.0
76
77 The benchmarks can be found in the [`/bench`](/bench) directory. They are separated into two categories:
78
79 * `basic` – compares an object comprised of `String`, `Number`, `Date`, `Array`, and `Object` values.
80 * `complex` – like `basic`, but adds `RegExp`, `Map`, `Set`, and `Uint8Array` values.
81
82 > **Note:** Only candidates that pass validation step(s) are listed. <br>For example, `fast-deep-equal/es6` handles `Set` and `Map` values, but uses _referential equality_ while those listed use _value equality_.
83
84 ```
85 Load times:
86 assert 0.109ms
87 util 0.006ms
88 fast-deep-equal 0.479ms
89 lodash/isequal 22.826ms
90 nano-equal 0.417ms
91 dequal 0.396ms
92 dequal/lite 0.264ms
93
94 Benchmark :: basic
95 assert.deepStrictEqual x 325,262 ops/sec ±0.57% (94 runs sampled)
96 util.isDeepStrictEqual x 318,812 ops/sec ±0.87% (94 runs sampled)
97 fast-deep-equal x 1,332,393 ops/sec ±0.36% (93 runs sampled)
98 lodash.isEqual x 269,129 ops/sec ±0.59% (95 runs sampled)
99 nano-equal x 1,122,053 ops/sec ±0.36% (96 runs sampled)
100 dequal/lite x 1,700,972 ops/sec ±0.31% (94 runs sampled)
101 dequal x 1,698,972 ops/sec ±0.63% (97 runs sampled)
102
103 Benchmark :: complex
104 assert.deepStrictEqual x 124,518 ops/sec ±0.64% (96 runs sampled)
105 util.isDeepStrictEqual x 125,113 ops/sec ±0.24% (96 runs sampled)
106 lodash.isEqual x 58,677 ops/sec ±0.49% (96 runs sampled)
107 dequal x 345,386 ops/sec ±0.27% (96 runs sampled)
108 ```
109
110 ## License
111
112 MIT © [Luke Edwards](https://lukeed.com)