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.
Files changed (49) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +58 -42
  3. package/dist/fast-equals.cjs.js +101 -210
  4. package/dist/fast-equals.cjs.js.map +1 -1
  5. package/dist/fast-equals.esm.js +101 -210
  6. package/dist/fast-equals.esm.js.map +1 -1
  7. package/dist/fast-equals.js +103 -212
  8. package/dist/fast-equals.js.map +1 -1
  9. package/dist/fast-equals.min.js +1 -1
  10. package/dist/fast-equals.mjs +101 -210
  11. package/dist/fast-equals.mjs.map +1 -1
  12. package/package.json +40 -41
  13. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
  14. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +0 -1
  15. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/code/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
  16. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
  17. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +0 -1
  18. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/semanticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
  19. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
  20. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/cb395dc6899b78eb42b4fab9df67376a0a00bf80 +0 -1
  21. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/syntacticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
  22. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
  23. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
  24. package/.rpt2_cache/rpt2_3c5f4e5db6faf852c13e3cd5e0db7a72d0e60a69/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
  25. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/0ab301188498506f5c998a00679f29b8929634e4 +0 -1
  26. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
  27. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/code/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
  28. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/0ab301188498506f5c998a00679f29b8929634e4 +0 -1
  29. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
  30. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/semanticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
  31. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/0ab301188498506f5c998a00679f29b8929634e4 +0 -1
  32. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/1d20cee756560ed06433a2e7dba9165f54487f2a +0 -1
  33. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/syntacticDiagnostics/cache/d800d7a0e39da81c91ab9c5059068c29ebc83792 +0 -1
  34. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/6982fa2ac1e62f4aebb1debc73977393caa0d5a4 +0 -0
  35. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
  36. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
  37. package/.rpt2_cache/rpt2_6a9ad0d85cd0ed74f9b918d742c78fdbe81d2201/types/cache/e578d3be8d82631bd5cd8272d6aa5a54ba064304 +0 -0
  38. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +0 -1
  39. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +0 -1
  40. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/code/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +0 -1
  41. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +0 -1
  42. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +0 -1
  43. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/semanticDiagnostics/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +0 -1
  44. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/82edcf6c99dc3d5802a5a8d3dbfc69f1048b520f +0 -1
  45. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/eb02971c7d2972b89cd15754372a7b9a0b328a30 +0 -1
  46. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/syntacticDiagnostics/cache/f6056671db45d89ddf3a27b7cf6d454993cec47b +0 -1
  47. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/c0f16c9111806a91c6ae4b5d0b138e4841adf7c9 +0 -0
  48. package/.rpt2_cache/rpt2_cbc4c616fc0ab8863b2f9b3be2cc7ae6306d679d/types/cache/c9f40676a1b140ebc96dde967251686b673a9961 +0 -0
  49. 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 ~1.3kB when minified and gzipped.
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
- - [Usage](#usage)
23
- - [Specific builds](#specific-builds)
24
- - [Available methods](#available-methods)
25
- - [deepEqual](#deepequal)
26
- - [shallowEqual](#shallowequal)
27
- - [sameValueZeroEqual](#samevaluezeroequal)
28
- - [circularDeepEqual](#circulardeepequal)
29
- - [circularShallowEqual](#circularshallowequal)
30
- - [createCustomEqual](#createcustomequal)
31
- - [Benchmarks](#benchmarks)
32
- - [Development](#development)
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
- #### Specific builds
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
- #### deepEqual
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
- #### shallowEqual
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
- #### sameValueZeroEqual
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
- #### circularDeepEqual
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
- #### circularShallowEqual
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
- #### createCustomEqual
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(deepEqual => {
175
- return (objectA, objectB, meta) => {
176
- return (
177
- objectA.foo === meta ||
178
- objectB.foo === meta ||
179
- deepEqual(objectA, objectB, meta)
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 8-core Arch Linux laptop with 16GB of memory using NodeJS version `10.15.3`, and are based on averages of running comparisons based deep equality on the following object types:
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** | **142,730** |
207
- | nano-equal | 115,530 |
208
- | shallow-equal-fuzzy | 102,633 |
209
- | fast-deep-equal | 102,335 |
210
- | react-fast-compare | 100,036 |
211
- | **fast-equals (circular)** | **79,589** |
212
- | underscore.isEqual | 63,390 |
213
- | deep-equal | 48,783 |
214
- | lodash.isEqual | 24,456 |
215
- | deep-eql | 24,196 |
216
- | assert.deepStrictEqual | 1,382 |
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. `Map`s, `Promise`s, and `Set`s were excluded from the benchmark entirely because no library other than `deep-eql` fully supported their comparison. The same logic applies to `react` elements (which can be circular objects), but simple elements are non-circular objects so I kept the `react` comparison very basic to allow it to be included.
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