fast-equals 4.0.3 → 5.0.0-beta.1

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 (71) hide show
  1. package/.babelrc +34 -0
  2. package/.prettierrc +4 -0
  3. package/CHANGELOG.md +39 -0
  4. package/README.md +146 -39
  5. package/build/rollup/config.base.js +49 -0
  6. package/build/rollup/config.cjs.js +10 -0
  7. package/build/rollup/config.esm.js +10 -0
  8. package/build/rollup/config.min.js +13 -0
  9. package/build/rollup/config.umd.js +10 -0
  10. package/build/tsconfig/base.json +32 -0
  11. package/build/tsconfig/cjs.json +8 -0
  12. package/build/tsconfig/declarations.json +9 -0
  13. package/build/tsconfig/esm.json +8 -0
  14. package/build/tsconfig/min.json +8 -0
  15. package/build/tsconfig/umd.json +8 -0
  16. package/build/webpack.config.js +57 -0
  17. package/dist/cjs/index.cjs +510 -0
  18. package/dist/cjs/index.cjs.map +1 -0
  19. package/dist/cjs/types/comparator.d.ts +2 -0
  20. package/dist/cjs/types/equals.d.ts +46 -0
  21. package/dist/cjs/types/index.d.ts +56 -0
  22. package/dist/cjs/types/internalTypes.d.ts +36 -0
  23. package/dist/cjs/types/utils.d.ts +19 -0
  24. package/dist/esm/index.mjs +499 -0
  25. package/dist/esm/index.mjs.map +1 -0
  26. package/dist/esm/types/comparator.d.ts +2 -0
  27. package/dist/esm/types/equals.d.ts +46 -0
  28. package/dist/esm/types/index.d.ts +56 -0
  29. package/dist/esm/types/internalTypes.d.ts +36 -0
  30. package/dist/esm/types/utils.d.ts +19 -0
  31. package/dist/min/index.js +1 -0
  32. package/dist/min/types/comparator.d.ts +2 -0
  33. package/dist/min/types/equals.d.ts +46 -0
  34. package/dist/min/types/index.d.ts +56 -0
  35. package/dist/min/types/internalTypes.d.ts +36 -0
  36. package/dist/min/types/utils.d.ts +19 -0
  37. package/dist/umd/index.js +516 -0
  38. package/dist/umd/index.js.map +1 -0
  39. package/dist/umd/types/comparator.d.ts +2 -0
  40. package/dist/umd/types/equals.d.ts +46 -0
  41. package/dist/umd/types/index.d.ts +56 -0
  42. package/dist/umd/types/internalTypes.d.ts +36 -0
  43. package/dist/umd/types/utils.d.ts +19 -0
  44. package/index.d.ts +62 -55
  45. package/package.json +59 -38
  46. package/recipes/explicit-property-check.md +4 -6
  47. package/recipes/legacy-circular-equal-support.md +28 -20
  48. package/recipes/legacy-regexp-support.md +15 -16
  49. package/recipes/non-standard-properties.md +35 -23
  50. package/recipes/using-meta-in-comparison.md +10 -13
  51. package/src/comparator.ts +43 -40
  52. package/src/equals.ts +263 -0
  53. package/src/index.ts +183 -79
  54. package/src/internalTypes.ts +74 -0
  55. package/src/utils.ts +42 -49
  56. package/dist/fast-equals.cjs.js +0 -432
  57. package/dist/fast-equals.cjs.js.map +0 -1
  58. package/dist/fast-equals.esm.js +0 -422
  59. package/dist/fast-equals.esm.js.map +0 -1
  60. package/dist/fast-equals.js +0 -438
  61. package/dist/fast-equals.js.map +0 -1
  62. package/dist/fast-equals.min.js +0 -1
  63. package/dist/fast-equals.mjs +0 -422
  64. package/dist/fast-equals.mjs.map +0 -1
  65. package/recipes/strict-property-descriptor-check.md +0 -42
  66. package/src/arrays.ts +0 -36
  67. package/src/dates.ts +0 -12
  68. package/src/maps.ts +0 -66
  69. package/src/objects.ts +0 -62
  70. package/src/regexps.ts +0 -11
  71. package/src/sets.ts +0 -61
package/src/objects.ts DELETED
@@ -1,62 +0,0 @@
1
- import { createIsCircular } from './utils';
2
-
3
- import type { InternalEqualityComparator } from '../index.d';
4
-
5
- interface Dictionary<Value> {
6
- [key: string]: Value;
7
- $$typeof?: any;
8
- }
9
-
10
- const OWNER = '_owner';
11
- const { hasOwnProperty } = Object.prototype;
12
-
13
- /**
14
- * Whether the objects are equal in value.
15
- */
16
- export function areObjectsEqual(
17
- a: Dictionary<any>,
18
- b: Dictionary<any>,
19
- isEqual: InternalEqualityComparator<any>,
20
- meta: any,
21
- ): boolean {
22
- const keysA = Object.keys(a);
23
-
24
- let index = keysA.length;
25
-
26
- if (Object.keys(b).length !== index) {
27
- return false;
28
- }
29
-
30
- let key: string;
31
-
32
- // Decrementing `while` showed faster results than either incrementing or
33
- // decrementing `for` loop and than an incrementing `while` loop. Declarative
34
- // methods like `some` / `every` were not used to avoid incurring the garbage
35
- // cost of anonymous callbacks.
36
- while (index-- > 0) {
37
- key = keysA[index];
38
-
39
- if (key === OWNER) {
40
- const reactElementA = !!a.$$typeof;
41
- const reactElementB = !!b.$$typeof;
42
-
43
- if ((reactElementA || reactElementB) && reactElementA !== reactElementB) {
44
- return false;
45
- }
46
- }
47
-
48
- if (
49
- !hasOwnProperty.call(b, key) ||
50
- !isEqual(a[key], b[key], key, key, a, b, meta)
51
- ) {
52
- return false;
53
- }
54
- }
55
-
56
- return true;
57
- }
58
-
59
- /**
60
- * Whether the objects are equal in value, including circular references.
61
- */
62
- export const areObjectsEqualCircular = createIsCircular(areObjectsEqual);
package/src/regexps.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * Whether the regexps passed are equal in value.
3
- *
4
- * @NOTE
5
- * This is a standalone function instead of done inline in the comparator
6
- * to allow for overrides. An example of this would be supporting a
7
- * pre-ES2015 environment where the `flags` property is not available.
8
- */
9
- export function areRegExpsEqual(a: RegExp, b: RegExp): boolean {
10
- return a.source === b.source && a.flags === b.flags;
11
- }
package/src/sets.ts DELETED
@@ -1,61 +0,0 @@
1
- import { createIsCircular } from './utils';
2
-
3
- import type { InternalEqualityComparator } from '../index.d';
4
-
5
- /**
6
- * Whether the `Set`s are equal in value.
7
- */
8
- export function areSetsEqual(
9
- a: Set<any>,
10
- b: Set<any>,
11
- isEqual: InternalEqualityComparator<any>,
12
- meta: any,
13
- ): boolean {
14
- let isValueEqual = a.size === b.size;
15
-
16
- if (!isValueEqual) {
17
- return false;
18
- }
19
-
20
- if (!a.size) {
21
- return true;
22
- }
23
-
24
- // The use of `forEach()` is to avoid the transpilation cost of `for...of` comparisons, and
25
- // the inability to control the performance of the resulting code. It also avoids excessive
26
- // iteration compared to doing comparisons of `keys()` and `values()`. As a result, though,
27
- // we cannot short-circuit the iterations; bookkeeping must be done to short-circuit the
28
- // equality checks themselves.
29
-
30
- const matchedIndices: Record<number, true> = {};
31
-
32
- a.forEach((aValue, aKey) => {
33
- if (!isValueEqual) {
34
- return;
35
- }
36
-
37
- let hasMatch = false;
38
- let matchIndex = 0;
39
-
40
- b.forEach((bValue, bKey) => {
41
- if (
42
- !hasMatch &&
43
- !matchedIndices[matchIndex] &&
44
- (hasMatch = isEqual(aValue, bValue, aKey, bKey, a, b, meta))
45
- ) {
46
- matchedIndices[matchIndex] = true;
47
- }
48
-
49
- matchIndex++;
50
- });
51
-
52
- isValueEqual = hasMatch;
53
- });
54
-
55
- return isValueEqual;
56
- }
57
-
58
- /**
59
- * Whether the `Set`s are equal in value, including circular references.
60
- */
61
- export const areSetsEqualCircular = createIsCircular(areSetsEqual);