@cjser/fast-equals__v5_4_1 5.4.1-cjser.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +482 -0
- package/dist/cjs/index.cjs +653 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +211 -0
- package/dist/es/index.d.mts +211 -0
- package/dist/es/index.mjs +642 -0
- package/dist/es/index.mjs.map +1 -0
- package/dist/umd/index.d.ts +211 -0
- package/dist/umd/index.js +659 -0
- package/dist/umd/index.js.map +1 -0
- package/dist-cjser/index.cjs +452 -0
- package/index.d.ts +211 -0
- package/package.json +177 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tony Quetano
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
# fast-equals
|
|
2
|
+
|
|
3
|
+
<img src="https://img.shields.io/badge/build-passing-brightgreen.svg"/>
|
|
4
|
+
<img src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg"/>
|
|
5
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg"/>
|
|
6
|
+
|
|
7
|
+
Perform [blazing fast](#benchmarks) equality comparisons (either deep or shallow) on two objects passed, while also
|
|
8
|
+
maintaining a high degree of flexibility for various implementation use-cases. It has no dependencies, and is ~2kB when
|
|
9
|
+
minified and gzipped.
|
|
10
|
+
|
|
11
|
+
The following types are handled out-of-the-box:
|
|
12
|
+
|
|
13
|
+
- Plain objects (including `react` elements and `Arguments`)
|
|
14
|
+
- Arrays
|
|
15
|
+
- `ArrayBuffer` / `TypedArray` / `DataView` instances
|
|
16
|
+
- `Date` objects
|
|
17
|
+
- `RegExp` objects
|
|
18
|
+
- `Map` / `Set` iterables
|
|
19
|
+
- `Promise` objects
|
|
20
|
+
- Primitive wrappers (`new Boolean()` / `new Number()` / `new String()`)
|
|
21
|
+
- Custom class instances, including subclasses of native classes
|
|
22
|
+
|
|
23
|
+
Methods are available for deep, shallow, or referential equality comparison. In addition, you can opt into support for
|
|
24
|
+
circular objects, or performing a "strict" comparison with unconventional property definition, or both. You can also
|
|
25
|
+
customize any specific type comparison based on your application's use-cases.
|
|
26
|
+
|
|
27
|
+
## Table of contents
|
|
28
|
+
|
|
29
|
+
- [fast-equals](#fast-equals)
|
|
30
|
+
- [Table of contents](#table-of-contents)
|
|
31
|
+
- [Usage](#usage)
|
|
32
|
+
- [Specific builds](#specific-builds)
|
|
33
|
+
- [Available methods](#available-methods)
|
|
34
|
+
- [deepEqual](#deepequal)
|
|
35
|
+
- [Comparing `Map`s](#comparing-maps)
|
|
36
|
+
- [shallowEqual](#shallowequal)
|
|
37
|
+
- [sameValueZeroEqual](#samevaluezeroequal)
|
|
38
|
+
- [circularDeepEqual](#circulardeepequal)
|
|
39
|
+
- [circularShallowEqual](#circularshallowequal)
|
|
40
|
+
- [strictDeepEqual](#strictdeepequal)
|
|
41
|
+
- [strictShallowEqual](#strictshallowequal)
|
|
42
|
+
- [strictCircularDeepEqual](#strictcirculardeepequal)
|
|
43
|
+
- [strictCircularShallowEqual](#strictcircularshallowequal)
|
|
44
|
+
- [createCustomEqual](#createcustomequal)
|
|
45
|
+
- [unknownTagComparators](#unknowntagcomparators)
|
|
46
|
+
- [Recipes](#recipes)
|
|
47
|
+
- [Benchmarks](#benchmarks)
|
|
48
|
+
- [Development](#development)
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { deepEqual } from 'fast-equals';
|
|
54
|
+
|
|
55
|
+
console.log(deepEqual({ foo: 'bar' }, { foo: 'bar' })); // true
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Specific builds
|
|
59
|
+
|
|
60
|
+
By default, npm should resolve the correct build of the package based on your consumption (ESM vs CommonJS). However, if
|
|
61
|
+
you want to force use of a specific build, they can be located here:
|
|
62
|
+
|
|
63
|
+
- ESM => `fast-equals/dist/esm/index.mjs`
|
|
64
|
+
- CommonJS => `fast-equals/dist/cjs/index.cjs`
|
|
65
|
+
- UMD => `fast-equals/dist/umd/index.js`
|
|
66
|
+
- Minified UMD => `fast-equals/dist/min/index.js`
|
|
67
|
+
|
|
68
|
+
If you are having issues loading a specific build type,
|
|
69
|
+
[please file an issue](https://github.com/planttheidea/fast-equals/issues).
|
|
70
|
+
|
|
71
|
+
## Available methods
|
|
72
|
+
|
|
73
|
+
### deepEqual
|
|
74
|
+
|
|
75
|
+
Performs a deep equality comparison on the two objects passed and returns a boolean representing the value equivalency
|
|
76
|
+
of the objects.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { deepEqual } from 'fast-equals';
|
|
80
|
+
|
|
81
|
+
const objectA = { foo: { bar: 'baz' } };
|
|
82
|
+
const objectB = { foo: { bar: 'baz' } };
|
|
83
|
+
|
|
84
|
+
console.log(objectA === objectB); // false
|
|
85
|
+
console.log(deepEqual(objectA, objectB)); // true
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### Comparing `Map`s
|
|
89
|
+
|
|
90
|
+
`Map` objects support complex keys (objects, Arrays, etc.), however
|
|
91
|
+
[the spec for key lookups in `Map` are based on `SameZeroValue`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#key_equality).
|
|
92
|
+
If the spec were followed for comparison, the following would always be `false`:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const mapA = new Map([[{ foo: 'bar' }, { baz: 'quz' }]]);
|
|
96
|
+
const mapB = new Map([[{ foo: 'bar' }, { baz: 'quz' }]]);
|
|
97
|
+
|
|
98
|
+
deepEqual(mapA, mapB);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
To support true deep equality of all contents, `fast-equals` will perform a deep equality comparison for key and value
|
|
102
|
+
parirs. Therefore, the above would be `true`.
|
|
103
|
+
|
|
104
|
+
### shallowEqual
|
|
105
|
+
|
|
106
|
+
Performs a shallow equality comparison on the two objects passed and returns a boolean representing the value
|
|
107
|
+
equivalency of the objects.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { shallowEqual } from 'fast-equals';
|
|
111
|
+
|
|
112
|
+
const nestedObject = { bar: 'baz' };
|
|
113
|
+
|
|
114
|
+
const objectA = { foo: nestedObject };
|
|
115
|
+
const objectB = { foo: nestedObject };
|
|
116
|
+
const objectC = { foo: { bar: 'baz' } };
|
|
117
|
+
|
|
118
|
+
console.log(objectA === objectB); // false
|
|
119
|
+
console.log(shallowEqual(objectA, objectB)); // true
|
|
120
|
+
console.log(shallowEqual(objectA, objectC)); // false
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### sameValueZeroEqual
|
|
124
|
+
|
|
125
|
+
Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) comparison on the two
|
|
126
|
+
objects passed and returns a boolean representing the value equivalency of the objects. In simple terms, this means
|
|
127
|
+
either strictly equal or both `NaN`.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { sameValueZeroEqual } from 'fast-equals';
|
|
131
|
+
|
|
132
|
+
const mainObject = { foo: NaN, bar: 'baz' };
|
|
133
|
+
|
|
134
|
+
const objectA = 'baz';
|
|
135
|
+
const objectB = NaN;
|
|
136
|
+
const objectC = { foo: NaN, bar: 'baz' };
|
|
137
|
+
|
|
138
|
+
console.log(sameValueZeroEqual(mainObject.bar, objectA)); // true
|
|
139
|
+
console.log(sameValueZeroEqual(mainObject.foo, objectB)); // true
|
|
140
|
+
console.log(sameValueZeroEqual(mainObject, objectC)); // false
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### circularDeepEqual
|
|
144
|
+
|
|
145
|
+
Performs the same comparison as `deepEqual` but supports circular objects. It is slower than `deepEqual`, so only use if
|
|
146
|
+
you know circular objects are present.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
function Circular(value) {
|
|
150
|
+
this.me = {
|
|
151
|
+
deeply: {
|
|
152
|
+
nested: {
|
|
153
|
+
reference: this,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
value,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
console.log(circularDeepEqual(new Circular('foo'), new Circular('foo'))); // true
|
|
161
|
+
console.log(circularDeepEqual(new Circular('foo'), new Circular('bar'))); // false
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Just as with `deepEqual`, [both keys and values are compared for deep equality](#comparing-maps).
|
|
165
|
+
|
|
166
|
+
### circularShallowEqual
|
|
167
|
+
|
|
168
|
+
Performs the same comparison as `shallowequal` but supports circular objects. It is slower than `shallowEqual`, so only
|
|
169
|
+
use if you know circular objects are present.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
const array = ['foo'];
|
|
173
|
+
|
|
174
|
+
array.push(array);
|
|
175
|
+
|
|
176
|
+
console.log(circularShallowEqual(array, ['foo', array])); // true
|
|
177
|
+
console.log(circularShallowEqual(array, [array])); // false
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### strictDeepEqual
|
|
181
|
+
|
|
182
|
+
Performs the same comparison as `deepEqual` but performs a strict comparison of the objects. In this includes:
|
|
183
|
+
|
|
184
|
+
- Checking symbol properties
|
|
185
|
+
- Checking non-enumerable properties in object comparisons
|
|
186
|
+
- Checking full descriptor of properties on the object to match
|
|
187
|
+
- Checking non-index properties on arrays
|
|
188
|
+
- Checking non-key properties on `Map` / `Set` objects
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
const array = [{ foo: 'bar' }];
|
|
192
|
+
const otherArray = [{ foo: 'bar' }];
|
|
193
|
+
|
|
194
|
+
array.bar = 'baz';
|
|
195
|
+
otherArray.bar = 'baz';
|
|
196
|
+
|
|
197
|
+
console.log(strictDeepEqual(array, otherArray)); // true;
|
|
198
|
+
console.log(strictDeepEqual(array, [{ foo: 'bar' }])); // false;
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### strictShallowEqual
|
|
202
|
+
|
|
203
|
+
Performs the same comparison as `shallowEqual` but performs a strict comparison of the objects. In this includes:
|
|
204
|
+
|
|
205
|
+
- Checking non-enumerable properties in object comparisons
|
|
206
|
+
- Checking full descriptor of properties on the object to match
|
|
207
|
+
- Checking non-index properties on arrays
|
|
208
|
+
- Checking non-key properties on `Map` / `Set` objects
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
const array = ['foo'];
|
|
212
|
+
const otherArray = ['foo'];
|
|
213
|
+
|
|
214
|
+
array.bar = 'baz';
|
|
215
|
+
otherArray.bar = 'baz';
|
|
216
|
+
|
|
217
|
+
console.log(strictDeepEqual(array, otherArray)); // true;
|
|
218
|
+
console.log(strictDeepEqual(array, ['foo'])); // false;
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### strictCircularDeepEqual
|
|
222
|
+
|
|
223
|
+
Performs the same comparison as `circularDeepEqual` but performs a strict comparison of the objects. In this includes:
|
|
224
|
+
|
|
225
|
+
- Checking `Symbol` properties on the object
|
|
226
|
+
- Checking non-enumerable properties in object comparisons
|
|
227
|
+
- Checking full descriptor of properties on the object to match
|
|
228
|
+
- Checking non-index properties on arrays
|
|
229
|
+
- Checking non-key properties on `Map` / `Set` objects
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
function Circular(value) {
|
|
233
|
+
this.me = {
|
|
234
|
+
deeply: {
|
|
235
|
+
nested: {
|
|
236
|
+
reference: this,
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
value,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const first = new Circular('foo');
|
|
244
|
+
|
|
245
|
+
Object.defineProperty(first, 'bar', {
|
|
246
|
+
enumerable: false,
|
|
247
|
+
value: 'baz',
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const second = new Circular('foo');
|
|
251
|
+
|
|
252
|
+
Object.defineProperty(second, 'bar', {
|
|
253
|
+
enumerable: false,
|
|
254
|
+
value: 'baz',
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
console.log(circularDeepEqual(first, second)); // true
|
|
258
|
+
console.log(circularDeepEqual(first, new Circular('foo'))); // false
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### strictCircularShallowEqual
|
|
262
|
+
|
|
263
|
+
Performs the same comparison as `circularShallowEqual` but performs a strict comparison of the objects. In this
|
|
264
|
+
includes:
|
|
265
|
+
|
|
266
|
+
- Checking non-enumerable properties in object comparisons
|
|
267
|
+
- Checking full descriptor of properties on the object to match
|
|
268
|
+
- Checking non-index properties on arrays
|
|
269
|
+
- Checking non-key properties on `Map` / `Set` objects
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
const array = ['foo'];
|
|
273
|
+
const otherArray = ['foo'];
|
|
274
|
+
|
|
275
|
+
array.push(array);
|
|
276
|
+
otherArray.push(otherArray);
|
|
277
|
+
|
|
278
|
+
array.bar = 'baz';
|
|
279
|
+
otherArray.bar = 'baz';
|
|
280
|
+
|
|
281
|
+
console.log(circularShallowEqual(array, otherArray)); // true
|
|
282
|
+
console.log(circularShallowEqual(array, ['foo', array])); // false
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### createCustomEqual
|
|
286
|
+
|
|
287
|
+
Creates a custom equality comparator that will be used on nested values in the object. Unlike `deepEqual` and
|
|
288
|
+
`shallowEqual`, this is a factory method that receives the default options used internally, and allows you to override
|
|
289
|
+
the defaults as needed. This is generally for extreme edge-cases, or supporting legacy environments.
|
|
290
|
+
|
|
291
|
+
The signature is as follows:
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
interface Cache<Key extends object, Value> {
|
|
295
|
+
delete(key: Key): boolean;
|
|
296
|
+
get(key: Key): Value | undefined;
|
|
297
|
+
set(key: Key, value: any): any;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
interface ComparatorConfig<Meta> {
|
|
301
|
+
areArraysEqual: TypeEqualityComparator<any[], Meta>;
|
|
302
|
+
areDatesEqual: TypeEqualityComparator<Date, Meta>;
|
|
303
|
+
areErrorsEqual: TypeEqualityComparator<Error, Meta>;
|
|
304
|
+
areFunctionsEqual: TypeEqualityComparator<(...args: any[]) => any, Meta>;
|
|
305
|
+
areMapsEqual: TypeEqualityComparator<Map<any, any>, Meta>;
|
|
306
|
+
areObjectsEqual: TypeEqualityComparator<Record<string, any>, Meta>;
|
|
307
|
+
arePrimitiveWrappersEqual: TypeEqualityComparator<boolean | string | number, Meta>;
|
|
308
|
+
areRegExpsEqual: TypeEqualityComparator<RegExp, Meta>;
|
|
309
|
+
areSetsEqual: TypeEqualityComparator<Set<any>, Meta>;
|
|
310
|
+
areTypedArraysEqual: TypeEqualityComparator<TypedArray, Meta>;
|
|
311
|
+
areUrlsEqual: TypeEqualityComparator<URL, Meta>;
|
|
312
|
+
unknownTagComparators: Record<string, TypeEqualityComparator<string, any>>;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function createCustomEqual<Meta>(options: {
|
|
316
|
+
circular?: boolean;
|
|
317
|
+
createCustomConfig?: (defaultConfig: ComparatorConfig<Meta>) => Partial<ComparatorConfig<Meta>>;
|
|
318
|
+
createInternalComparator?: (
|
|
319
|
+
compare: <A, B>(a: A, b: B, state: State<Meta>) => boolean,
|
|
320
|
+
) => (a: any, b: any, indexOrKeyA: any, indexOrKeyB: any, parentA: any, parentB: any, state: State<Meta>) => boolean;
|
|
321
|
+
createState?: () => { cache?: Cache; meta?: Meta };
|
|
322
|
+
strict?: boolean;
|
|
323
|
+
}): <A, B>(a: A, b: B) => boolean;
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Create a custom equality comparator. This allows complete control over building a bespoke equality method, in case your
|
|
327
|
+
use-case requires a higher degree of performance, legacy environment support, or any other non-standard usage. The
|
|
328
|
+
[recipes](#recipes) provide examples of use in different use-cases, but if you have a specific goal in mind and would
|
|
329
|
+
like assistance feel free to [file an issue](https://github.com/planttheidea/fast-equals/issues).
|
|
330
|
+
|
|
331
|
+
_**NOTE**: `Map` implementations compare equality for both keys and value. When using a custom comparator and comparing
|
|
332
|
+
equality of the keys, the iteration index is provided as both `indexOrKeyA` and `indexOrKeyB` to help use-cases where
|
|
333
|
+
ordering of keys matters to equality._
|
|
334
|
+
|
|
335
|
+
#### unknownTagComparators
|
|
336
|
+
|
|
337
|
+
If you want to compare objects that have a custom `@@toStringTag`, you can provide a map of the custom tags you want to
|
|
338
|
+
support via the `unknownTagComparators` option. See [this recipe]('./recipes/special-objects.md) for an example.
|
|
339
|
+
|
|
340
|
+
#### Recipes
|
|
341
|
+
|
|
342
|
+
Some recipes have been created to provide examples of use-cases for `createCustomEqual`. Even if not directly applicable
|
|
343
|
+
to the problem you are solving, they can offer guidance of how to structure your solution.
|
|
344
|
+
|
|
345
|
+
- [Legacy environment support for `RegExp` comparators](./recipes/legacy-regexp-support.md)
|
|
346
|
+
- [Explicit property check](./recipes/explicit-property-check.md)
|
|
347
|
+
- [Using `meta` in comparison](./recipes//using-meta-in-comparison.md)
|
|
348
|
+
- [Comparing non-standard properties](./recipes/non-standard-properties.md)
|
|
349
|
+
- [Strict property descriptor comparison](./recipes/strict-property-descriptor-check.md)
|
|
350
|
+
- [Legacy environment support for circualr equal comparators](./recipes/legacy-circular-equal-support.md)
|
|
351
|
+
- [Custom `@@toStringTag` support](./recipes/special-objects.md)
|
|
352
|
+
|
|
353
|
+
## Benchmarks
|
|
354
|
+
|
|
355
|
+
All benchmarks were performed on an i9-11900H Ubuntu Linux 24.04 laptop with 64GB of memory using NodeJS version
|
|
356
|
+
`20.17.0`, and are based on averages of running comparisons based deep equality on the following object types:
|
|
357
|
+
|
|
358
|
+
- Primitives (`String`, `Number`, `null`, `undefined`)
|
|
359
|
+
- `Function`
|
|
360
|
+
- `Object`
|
|
361
|
+
- `Array`
|
|
362
|
+
- `Date`
|
|
363
|
+
- `RegExp`
|
|
364
|
+
- `react` elements
|
|
365
|
+
- A mixed object with a combination of all the above types
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
Testing mixed objects equal...
|
|
369
|
+
┌────────────────────────────────────────┬────────────────┐
|
|
370
|
+
│ Name │ Ops / sec │
|
|
371
|
+
├────────────────────────────────────────┼────────────────┤
|
|
372
|
+
│ fast-equals (passed) │ 1416193.769468 │
|
|
373
|
+
├────────────────────────────────────────┼────────────────┤
|
|
374
|
+
│ fast-deep-equal (passed) │ 1284824.583215 │
|
|
375
|
+
├────────────────────────────────────────┼────────────────┤
|
|
376
|
+
│ react-fast-compare (passed) │ 1246947.505444 │
|
|
377
|
+
├────────────────────────────────────────┼────────────────┤
|
|
378
|
+
│ shallow-equal-fuzzy (passed) │ 1238082.379207 │
|
|
379
|
+
├────────────────────────────────────────┼────────────────┤
|
|
380
|
+
│ nano-equal (failed) │ 946782.33704 │
|
|
381
|
+
├────────────────────────────────────────┼────────────────┤
|
|
382
|
+
│ dequal/lite (passed) │ 758213.632866 │
|
|
383
|
+
├────────────────────────────────────────┼────────────────┤
|
|
384
|
+
│ dequal (passed) │ 756789.655029 │
|
|
385
|
+
├────────────────────────────────────────┼────────────────┤
|
|
386
|
+
│ fast-equals (circular) (passed) │ 726093.253185 │
|
|
387
|
+
├────────────────────────────────────────┼────────────────┤
|
|
388
|
+
│ underscore.isEqual (passed) │ 489748.701783 │
|
|
389
|
+
├────────────────────────────────────────┼────────────────┤
|
|
390
|
+
│ assert.deepStrictEqual (passed) │ 453761.890107 │
|
|
391
|
+
├────────────────────────────────────────┼────────────────┤
|
|
392
|
+
│ lodash.isEqual (passed) │ 288264.867811 │
|
|
393
|
+
├────────────────────────────────────────┼────────────────┤
|
|
394
|
+
│ fast-equals (strict) (passed) │ 217221.619705 │
|
|
395
|
+
├────────────────────────────────────────┼────────────────┤
|
|
396
|
+
│ fast-equals (strict circular) (passed) │ 186916.942934 │
|
|
397
|
+
├────────────────────────────────────────┼────────────────┤
|
|
398
|
+
│ deep-eql (passed) │ 162487.877883 │
|
|
399
|
+
├────────────────────────────────────────┼────────────────┤
|
|
400
|
+
│ deep-equal (passed) │ 916.680714 │
|
|
401
|
+
└────────────────────────────────────────┴────────────────┘
|
|
402
|
+
|
|
403
|
+
Testing mixed objects not equal...
|
|
404
|
+
┌────────────────────────────────────────┬────────────────┐
|
|
405
|
+
│ Name │ Ops / sec │
|
|
406
|
+
├────────────────────────────────────────┼────────────────┤
|
|
407
|
+
│ fast-equals (passed) │ 4687012.640614 │
|
|
408
|
+
├────────────────────────────────────────┼────────────────┤
|
|
409
|
+
│ fast-deep-equal (passed) │ 3418170.156109 │
|
|
410
|
+
├────────────────────────────────────────┼────────────────┤
|
|
411
|
+
│ react-fast-compare (passed) │ 3283516.669966 │
|
|
412
|
+
├────────────────────────────────────────┼────────────────┤
|
|
413
|
+
│ fast-equals (circular) (passed) │ 3268062.099602 │
|
|
414
|
+
├────────────────────────────────────────┼────────────────┤
|
|
415
|
+
│ fast-equals (strict) (passed) │ 1747578.66456 │
|
|
416
|
+
├────────────────────────────────────────┼────────────────┤
|
|
417
|
+
│ fast-equals (strict circular) (passed) │ 1477873.624956 │
|
|
418
|
+
├────────────────────────────────────────┼────────────────┤
|
|
419
|
+
│ dequal/lite (passed) │ 1335397.839502 │
|
|
420
|
+
├────────────────────────────────────────┼────────────────┤
|
|
421
|
+
│ dequal (passed) │ 1319426.71146 │
|
|
422
|
+
├────────────────────────────────────────┼────────────────┤
|
|
423
|
+
│ shallow-equal-fuzzy (failed) │ 1237432.986615 │
|
|
424
|
+
├────────────────────────────────────────┼────────────────┤
|
|
425
|
+
│ nano-equal (passed) │ 1064383.319776 │
|
|
426
|
+
├────────────────────────────────────────┼────────────────┤
|
|
427
|
+
│ underscore.isEqual (passed) │ 920462.516736 │
|
|
428
|
+
├────────────────────────────────────────┼────────────────┤
|
|
429
|
+
│ lodash.isEqual (passed) │ 379370.998021 │
|
|
430
|
+
├────────────────────────────────────────┼────────────────┤
|
|
431
|
+
│ deep-eql (passed) │ 184111.383127 │
|
|
432
|
+
├────────────────────────────────────────┼────────────────┤
|
|
433
|
+
│ assert.deepStrictEqual (passed) │ 20775.59065 │
|
|
434
|
+
├────────────────────────────────────────┼────────────────┤
|
|
435
|
+
│ deep-equal (passed) │ 3678.51009 │
|
|
436
|
+
└────────────────────────────────────────┴────────────────┘
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Caveats that impact the benchmark (and accuracy of comparison):
|
|
440
|
+
|
|
441
|
+
- `Map`s, `Promise`s, and `Set`s were excluded from the benchmark entirely because no library other than `deep-eql`
|
|
442
|
+
fully supported their comparison
|
|
443
|
+
- `fast-deep-equal`, `react-fast-compare` and `nano-equal` throw on objects with `null` as prototype
|
|
444
|
+
(`Object.create(null)`)
|
|
445
|
+
- `assert.deepStrictEqual` does not support `NaN` or `SameValueZero` equality for dates
|
|
446
|
+
- `deep-eql` does not support `SameValueZero` equality for zero equality (positive and negative zero are not equal)
|
|
447
|
+
- `deep-equal` does not support `NaN` and does not strictly compare object type, or date / regexp values, nor uses
|
|
448
|
+
`SameValueZero` equality for dates
|
|
449
|
+
- `fast-deep-equal` does not support `NaN` or `SameValueZero` equality for dates
|
|
450
|
+
- `nano-equal` does not strictly compare object property structure, array length, or object type, nor `SameValueZero`
|
|
451
|
+
equality for dates
|
|
452
|
+
- `react-fast-compare` does not support `NaN` or `SameValueZero` equality for dates, and does not compare `function`
|
|
453
|
+
equality
|
|
454
|
+
- `shallow-equal-fuzzy` does not strictly compare object type or regexp values, nor `SameValueZero` equality for dates
|
|
455
|
+
- `underscore.isEqual` does not support `SameValueZero` equality for primitives or dates
|
|
456
|
+
|
|
457
|
+
All of these have the potential of inflating the respective library's numbers in comparison to `fast-equals`, but it was
|
|
458
|
+
the closest apples-to-apples comparison I could create of a reasonable sample size. It should be noted that `react`
|
|
459
|
+
elements can be circular objects, however simple elements are not; I kept the `react` comparison very basic to allow it
|
|
460
|
+
to be included.
|
|
461
|
+
|
|
462
|
+
## Development
|
|
463
|
+
|
|
464
|
+
Standard practice, clone the repo and `npm i` to get the dependencies. The following npm scripts are available:
|
|
465
|
+
|
|
466
|
+
- benchmark => run benchmark tests against other equality libraries
|
|
467
|
+
- build => build `main`, `module`, and `browser` distributables with `rollup`
|
|
468
|
+
- clean => run `rimraf` on the `dist` folder
|
|
469
|
+
- dev => start `vite` playground App
|
|
470
|
+
- dist => run `build`
|
|
471
|
+
- lint => run ESLint on all files in `src` folder (also runs on `dev` script)
|
|
472
|
+
- lint:fix => run `lint` script, but with auto-fixer
|
|
473
|
+
- prepublish:compile => run `lint`, `test:coverage`, `transpile:lib`, `transpile:es`, and `dist` scripts
|
|
474
|
+
- start => run `dev`
|
|
475
|
+
- test => run AVA with NODE_ENV=test on all files in `test` folder
|
|
476
|
+
- test:coverage => run same script as `test` with code coverage calculation via `nyc`
|
|
477
|
+
- test:watch => run same script as `test` but keep persistent watcher
|
|
478
|
+
|
|
479
|
+
## cjser
|
|
480
|
+
|
|
481
|
+
This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
|
|
482
|
+
Original repository: https://github.com/planttheidea/fast-equals
|