fast-equals 2.0.0 → 2.0.4
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/CHANGELOG.md +20 -0
- package/README.md +58 -42
- package/dist/fast-equals.cjs.js +101 -210
- package/dist/fast-equals.cjs.js.map +1 -1
- package/dist/fast-equals.esm.js +101 -210
- package/dist/fast-equals.esm.js.map +1 -1
- package/dist/fast-equals.js +103 -212
- package/dist/fast-equals.js.map +1 -1
- package/dist/fast-equals.min.js +1 -1
- package/dist/fast-equals.mjs +101 -210
- package/dist/fast-equals.mjs.map +1 -1
- package/package.json +40 -41
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +0 -1
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +0 -1
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +0 -1
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
- package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/0ab301188498506f5c998a00679f29b8929634e4 +0 -1
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/0ab301188498506f5c998a00679f29b8929634e4 +0 -1
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/0ab301188498506f5c998a00679f29b8929634e4 +0 -1
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/6982fa2ac1e62f4aebb1debc73977393caa0d5a4 +0 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
- package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +0 -1
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +0 -1
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +0 -1
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +0 -1
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +0 -1
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +0 -1
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +0 -1
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +0 -1
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +0 -1
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
- package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# fast-equals CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 2.0.4
|
|
4
|
+
|
|
5
|
+
- Fix [#58](https://github.com/planttheidea/fast-equals/issues/58) - duplicate entries in `Map` / `Set` can create false equality success
|
|
6
|
+
- [#60](https://github.com/planttheidea/fast-equals/issues/60) - Add documentation for key equality of `Map` being a part of `deepEqual`
|
|
7
|
+
|
|
8
|
+
## 2.0.3
|
|
9
|
+
|
|
10
|
+
- Fix [#50](https://github.com/planttheidea/fast-equals/pull/50) - copy-pasta in cacheable check
|
|
11
|
+
|
|
12
|
+
## 2.0.2
|
|
13
|
+
|
|
14
|
+
- Optimize iterables comparisons to not double-iterate
|
|
15
|
+
- Optimize loop-based comparisons for speed
|
|
16
|
+
- Improve cache handling in circular handlers
|
|
17
|
+
- Improve stability of memory by reducing variable instantiation
|
|
18
|
+
|
|
19
|
+
## 2.0.1
|
|
20
|
+
|
|
21
|
+
- Fix [#41](https://github.com/planttheidea/fast-equals/pull/41) - prevent `.rpt2_cache` directory from being published for better CI environment support (thanks [@herberttn](https://github.com/herberttn))
|
|
22
|
+
|
|
3
23
|
## 2.0.0
|
|
4
24
|
|
|
5
25
|
#### Breaking changes
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<img src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg"/>
|
|
5
5
|
<img src="https://img.shields.io/badge/license-MIT-blue.svg"/>
|
|
6
6
|
|
|
7
|
-
Perform [blazing fast](#benchmarks) equality comparisons (either deep or shallow) on two objects passed. It has no dependencies, and is ~
|
|
7
|
+
Perform [blazing fast](#benchmarks) equality comparisons (either deep or shallow) on two objects passed. It has no dependencies, and is ~1kB when minified and gzipped.
|
|
8
8
|
|
|
9
9
|
Unlike most equality validation libraries, the following types are handled out-of-the-box:
|
|
10
10
|
|
|
@@ -19,17 +19,20 @@ Starting with version `1.5.0`, circular objects are supported for both deep and
|
|
|
19
19
|
|
|
20
20
|
## Table of contents
|
|
21
21
|
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
24
|
-
- [
|
|
25
|
-
|
|
26
|
-
- [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- [
|
|
32
|
-
- [
|
|
22
|
+
- [fast-equals](#fast-equals)
|
|
23
|
+
- [Table of contents](#table-of-contents)
|
|
24
|
+
- [Usage](#usage)
|
|
25
|
+
- [Specific builds](#specific-builds)
|
|
26
|
+
- [Available methods](#available-methods)
|
|
27
|
+
- [deepEqual](#deepequal)
|
|
28
|
+
- [Comparing `Map`s](#comparing-maps)
|
|
29
|
+
- [shallowEqual](#shallowequal)
|
|
30
|
+
- [sameValueZeroEqual](#samevaluezeroequal)
|
|
31
|
+
- [circularDeepEqual](#circulardeepequal)
|
|
32
|
+
- [circularShallowEqual](#circularshallowequal)
|
|
33
|
+
- [createCustomEqual](#createcustomequal)
|
|
34
|
+
- [Benchmarks](#benchmarks)
|
|
35
|
+
- [Development](#development)
|
|
33
36
|
|
|
34
37
|
## Usage
|
|
35
38
|
|
|
@@ -49,7 +52,7 @@ import * as fe from 'fast-equals';
|
|
|
49
52
|
console.log(fe.deep({ foo: 'bar' }, { foo: 'bar' })); // true
|
|
50
53
|
```
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
### Specific builds
|
|
53
56
|
|
|
54
57
|
There are three builds, an ESM build for modern build systems / runtimes, a CommonJS build for traditional NodeJS environments, and a UMD build for legacy implementations. The ideal one will likely be chosen for you automatically, however if you want to use a specific build you can always import it directly:
|
|
55
58
|
|
|
@@ -64,7 +67,7 @@ There is also a pre-minified version of the UMD build available:
|
|
|
64
67
|
|
|
65
68
|
## Available methods
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
### deepEqual
|
|
68
71
|
|
|
69
72
|
Performs a deep equality comparison on the two objects passed and returns a boolean representing the value equivalency of the objects.
|
|
70
73
|
|
|
@@ -78,7 +81,20 @@ console.log(objectA === objectB); // false
|
|
|
78
81
|
console.log(deepEqual(objectA, objectB)); // true
|
|
79
82
|
```
|
|
80
83
|
|
|
81
|
-
####
|
|
84
|
+
#### Comparing `Map`s
|
|
85
|
+
|
|
86
|
+
`Map` objects support complex keys (objects, Arrays, etc.), however [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). If the spec were followed for comparison, the following would always be `false`:
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
const mapA = new Map([[{ foo: 'bar' }, { baz: 'quz' }]]);
|
|
90
|
+
const mapB = new Map([[{ foo: 'bar' }, { baz: 'quz' }]]);
|
|
91
|
+
|
|
92
|
+
deepEqual(mapA, mapB);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
To support true deep equality of all contents, `fast-equals` will perform a deep equality comparison for key and value parirs. Therefore, the above would be `true`.
|
|
96
|
+
|
|
97
|
+
### shallowEqual
|
|
82
98
|
|
|
83
99
|
Performs a shallow equality comparison on the two objects passed and returns a boolean representing the value equivalency of the objects.
|
|
84
100
|
|
|
@@ -96,7 +112,7 @@ console.log(shallowEqual(objectA, objectB)); // true
|
|
|
96
112
|
console.log(shallowEqual(objectA, objectC)); // false
|
|
97
113
|
```
|
|
98
114
|
|
|
99
|
-
|
|
115
|
+
### sameValueZeroEqual
|
|
100
116
|
|
|
101
117
|
Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) comparison on the two objects passed and returns a boolean representing the value equivalency of the objects. In simple terms, this means either strictly equal or both `NaN`.
|
|
102
118
|
|
|
@@ -114,7 +130,7 @@ console.log(sameValueZeroEqual(mainObject.foo, objectB)); // true
|
|
|
114
130
|
console.log(sameValueZeroEqual(mainObject, objectC)); // false
|
|
115
131
|
```
|
|
116
132
|
|
|
117
|
-
|
|
133
|
+
### circularDeepEqual
|
|
118
134
|
|
|
119
135
|
Performs the same comparison as `deepEqual` but supports circular objects. It is slower than `deepEqual`, so only use if you know circular objects are present.
|
|
120
136
|
|
|
@@ -134,7 +150,9 @@ console.log(circularDeepEqual(new Circular('foo'), new Circular('foo'))); // tru
|
|
|
134
150
|
console.log(circularDeepEqual(new Circular('foo'), new Circular('bar'))); // false
|
|
135
151
|
```
|
|
136
152
|
|
|
137
|
-
|
|
153
|
+
Just as with `deepEqual`, [both keys and values are compared for deep equality](#comparing-maps).
|
|
154
|
+
|
|
155
|
+
### circularShallowEqual
|
|
138
156
|
|
|
139
157
|
Performs the same comparison as `shallowequal` but supports circular objects. It is slower than `shallowEqual`, so only use if you know circular objects are present.
|
|
140
158
|
|
|
@@ -147,7 +165,7 @@ console.log(circularShallowEqual(array, ['foo', array])); // true
|
|
|
147
165
|
console.log(circularShallowEqual(array, [array])); // false
|
|
148
166
|
```
|
|
149
167
|
|
|
150
|
-
|
|
168
|
+
### createCustomEqual
|
|
151
169
|
|
|
152
170
|
Creates a custom equality comparator that will be used on nested values in the object. Unlike `deepEqual` and `shallowEqual`, this is a partial-application function that will receive the internal comparator and should return a function that compares two objects.
|
|
153
171
|
|
|
@@ -171,26 +189,23 @@ An example for a custom equality comparison that also checks against values in t
|
|
|
171
189
|
```javascript
|
|
172
190
|
import { createCustomEqual } from 'fast-equals';
|
|
173
191
|
|
|
174
|
-
const isDeepEqualOrFooMatchesMeta = createCustomEqual(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
);
|
|
181
|
-
};
|
|
182
|
-
});
|
|
192
|
+
const isDeepEqualOrFooMatchesMeta = createCustomEqual(
|
|
193
|
+
(deepEqual) => (objectA, objectB, meta) =>
|
|
194
|
+
objectA.foo === meta ||
|
|
195
|
+
objectB.foo === meta ||
|
|
196
|
+
deepEqual(objectA, objectB, meta),
|
|
197
|
+
);
|
|
183
198
|
|
|
184
199
|
const objectA = { foo: 'bar' };
|
|
185
200
|
const objectB = { foo: 'baz' };
|
|
186
201
|
const meta = 'bar';
|
|
187
202
|
|
|
188
|
-
console.log(isDeepEqualOrFooMatchesMeta(objectA, objectB)); // true
|
|
203
|
+
console.log(isDeepEqualOrFooMatchesMeta(objectA, objectB, meta)); // true
|
|
189
204
|
```
|
|
190
205
|
|
|
191
206
|
## Benchmarks
|
|
192
207
|
|
|
193
|
-
All benchmarks were performed on an i7
|
|
208
|
+
All benchmarks were performed on an i7-8650U Ubuntu Linux laptop with 24GB of memory using NodeJS version `12.19.1`, and are based on averages of running comparisons based deep equality on the following object types:
|
|
194
209
|
|
|
195
210
|
- Primitives (`String`, `Number`, `null`, `undefined`)
|
|
196
211
|
- `Function`
|
|
@@ -203,20 +218,21 @@ All benchmarks were performed on an i7 8-core Arch Linux laptop with 16GB of mem
|
|
|
203
218
|
|
|
204
219
|
| | Operations / second |
|
|
205
220
|
| -------------------------- | ------------------- |
|
|
206
|
-
| **fast-equals** | **
|
|
207
|
-
|
|
|
208
|
-
|
|
|
209
|
-
|
|
|
210
|
-
|
|
|
211
|
-
|
|
|
212
|
-
| underscore.isEqual |
|
|
213
|
-
|
|
|
214
|
-
|
|
|
215
|
-
|
|
|
216
|
-
|
|
|
221
|
+
| **fast-equals** | **153,880** |
|
|
222
|
+
| fast-deep-equal | 144,035 |
|
|
223
|
+
| react-fast-compare | 130,324 |
|
|
224
|
+
| nano-equal | 104,624 |
|
|
225
|
+
| **fast-equals (circular)** | **97,610** |
|
|
226
|
+
| shallow-equal-fuzzy | 83,946 |
|
|
227
|
+
| underscore.isEqual | 47,370 |
|
|
228
|
+
| lodash.isEqual | 25,053 |
|
|
229
|
+
| deep-eql | 22,146 |
|
|
230
|
+
| assert.deepStrictEqual | 532 |
|
|
231
|
+
| deep-equal | 209 |
|
|
217
232
|
|
|
218
233
|
Caveats that impact the benchmark (and accuracy of comparison):
|
|
219
234
|
|
|
235
|
+
- `Map`s, `Promise`s, and `Set`s were excluded from the benchmark entirely because no library other than `deep-eql` fully supported their comparison
|
|
220
236
|
- `assert.deepStrictEqual` does not support `NaN` or `SameValueZero` equality for dates
|
|
221
237
|
- `deep-eql` does not support `SameValueZero` equality for zero equality (positive and negative zero are not equal)
|
|
222
238
|
- `deep-equal` does not support `NaN` and does not strictly compare object type, or date / regexp values, nor uses `SameValueZero` equality for dates
|
|
@@ -226,7 +242,7 @@ Caveats that impact the benchmark (and accuracy of comparison):
|
|
|
226
242
|
- `shallow-equal-fuzzy` does not strictly compare object type or regexp values, nor `SameValueZero` equality for dates
|
|
227
243
|
- `underscore.isEqual` does not support `SameValueZero` equality for primitives or dates
|
|
228
244
|
|
|
229
|
-
All of these have the potential of inflating the respective library's numbers in comparison to `fast-equals`, but it was the closest apples-to-apples comparison I could create of a reasonable sample size.
|
|
245
|
+
All of these have the potential of inflating the respective library's numbers in comparison to `fast-equals`, but it was the closest apples-to-apples comparison I could create of a reasonable sample size. It should be noted that `react` elements can be circular objects, however simple elements are not; I kept the `react` comparison very basic to allow it to be included.
|
|
230
246
|
|
|
231
247
|
## Development
|
|
232
248
|
|