@longlast/equals 0.5.9 → 0.5.11

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/dist/index.d.ts CHANGED
@@ -39,7 +39,6 @@ export declare const equalsWith: Curried3<EqualsOptions, unknown, unknown, boole
39
39
  * Deeply compares two values, returning true if they're equal and false
40
40
  * otherwise. The following criteria are used to determine equality:
41
41
  *
42
- * - All values are equal to themselves.
43
42
  * - Primitives `a` and `b` are equal iff `Object.is(a, b)`. This is similar
44
43
  * to `===` comparison, but treats `NaN` as equal to `NaN` and `0` as
45
44
  * different from `-0`.
@@ -47,7 +46,7 @@ export declare const equalsWith: Curried3<EqualsOptions, unknown, unknown, boole
47
46
  * - RegExps are equal iff they have the same pattern and flags.
48
47
  * - Errors are equal iff they have the same class and message.
49
48
  * - Arrays are equal iff they have the same length and their corresponding
50
- * elements are equal (according to `equals`).
49
+ * elements are equal according to `equals`.
51
50
  * - Sets are equal iff they contain the same elements. Note that set
52
51
  * elements are _not_ deeply compared.
53
52
  * - Maps are equal iff they have the same set of keys, and their
@@ -56,10 +55,11 @@ export declare const equalsWith: Curried3<EqualsOptions, unknown, unknown, boole
56
55
  * - Partially applied functions (via {@link curry} or {@link partial-apply})
57
56
  * are equal iff they originate from the same function and their bound
58
57
  * arguments are equal according to `equals`.
58
+ * - Typed arrays are equal iff they have the same type, length, and values.
59
59
  * - Other objects are equal iff they have the same prototype (e.g. the same
60
60
  * class) and the same set of enumerable string-keyed properties, and the
61
- * values of their corresponding properties are equal (according to
62
- * `equals`).
61
+ * values of their corresponding properties are equal according to
62
+ * `equals`.
63
63
  *
64
64
  * You can customize how `equals()` compares values of a specific class by
65
65
  * using the {@link symbols.$equals $equals} symbol to define a method on that
package/dist/index.js CHANGED
@@ -2,7 +2,8 @@
2
2
  * @module equals
3
3
  */
4
4
  import { curry } from "@longlast/curry";
5
- import { $boundArguments, $equals, $getBoundArguments, $unapplied, } from "@longlast/symbols";
5
+ import { getBoundArguments, getUnapplied } from "@longlast/function-provenance";
6
+ import { $equals } from "@longlast/symbols";
6
7
  /**
7
8
  * @function
8
9
  * A version of {@link equals} that allows callers to override the default
@@ -47,10 +48,9 @@ function _equalsWith(options, a, b) {
47
48
  return true;
48
49
  }
49
50
  if (typeof a === "function" && typeof b === "function") {
50
- const aUnapplied = a[$unapplied];
51
- const bUnapplied = b[$unapplied];
52
- return (aUnapplied != null &&
53
- aUnapplied === bUnapplied &&
51
+ unsafeNarrow(a);
52
+ unsafeNarrow(b);
53
+ return (getUnapplied(a) === getUnapplied(b) &&
54
54
  _equalsWith(options, getBoundArguments(a), getBoundArguments(b)));
55
55
  }
56
56
  // If `a` is a primitive at this point, return false, since we already know
@@ -87,7 +87,6 @@ function _equalsWith(options, a, b) {
87
87
  unsafeNarrow(b);
88
88
  return a.size === b.size && [...a].every((v) => b.has(v));
89
89
  }
90
- // TODO: typed arrays
91
90
  if (mapConstructorString === aConstructorString) {
92
91
  unsafeNarrow(a);
93
92
  unsafeNarrow(b);
@@ -128,7 +127,6 @@ function _equalsWith(options, a, b) {
128
127
  * Deeply compares two values, returning true if they're equal and false
129
128
  * otherwise. The following criteria are used to determine equality:
130
129
  *
131
- * - All values are equal to themselves.
132
130
  * - Primitives `a` and `b` are equal iff `Object.is(a, b)`. This is similar
133
131
  * to `===` comparison, but treats `NaN` as equal to `NaN` and `0` as
134
132
  * different from `-0`.
@@ -136,7 +134,7 @@ function _equalsWith(options, a, b) {
136
134
  * - RegExps are equal iff they have the same pattern and flags.
137
135
  * - Errors are equal iff they have the same class and message.
138
136
  * - Arrays are equal iff they have the same length and their corresponding
139
- * elements are equal (according to `equals`).
137
+ * elements are equal according to `equals`.
140
138
  * - Sets are equal iff they contain the same elements. Note that set
141
139
  * elements are _not_ deeply compared.
142
140
  * - Maps are equal iff they have the same set of keys, and their
@@ -145,10 +143,11 @@ function _equalsWith(options, a, b) {
145
143
  * - Partially applied functions (via {@link curry} or {@link partial-apply})
146
144
  * are equal iff they originate from the same function and their bound
147
145
  * arguments are equal according to `equals`.
146
+ * - Typed arrays are equal iff they have the same type, length, and values.
148
147
  * - Other objects are equal iff they have the same prototype (e.g. the same
149
148
  * class) and the same set of enumerable string-keyed properties, and the
150
- * values of their corresponding properties are equal (according to
151
- * `equals`).
149
+ * values of their corresponding properties are equal according to
150
+ * `equals`.
152
151
  *
153
152
  * You can customize how `equals()` compares values of a specific class by
154
153
  * using the {@link symbols.$equals $equals} symbol to define a method on that
@@ -186,10 +185,6 @@ function _equalsWith(options, a, b) {
186
185
  */
187
186
  // TODO: clear function provenance on `equals`.
188
187
  export const equals = equalsWith({});
189
- function getBoundArguments(f) {
190
- // TODO: (pre-1.0.0) remove `f[$boundArguments]` fallback.
191
- return f[$getBoundArguments]?.() ?? f[$boundArguments];
192
- }
193
188
  function functionString(f) {
194
189
  if (typeof f !== "function") {
195
190
  return "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longlast/equals",
3
- "version": "0.5.9",
3
+ "version": "0.5.11",
4
4
  "description": "Deeply compares objects",
5
5
  "homepage": "https://longlast.js.org/",
6
6
  "license": "MIT",
@@ -17,8 +17,10 @@
17
17
  "#@longlast/equals": "./src/index.ts"
18
18
  },
19
19
  "dependencies": {
20
+ "@longlast/any-function": "^0.0.1",
20
21
  "@longlast/curry": "^0.5.0",
21
- "@longlast/symbols": "^1.0.0"
22
+ "@longlast/function-provenance": "^0.0.3",
23
+ "@longlast/symbols": "^1.1.0"
22
24
  },
23
25
  "devDependencies": {
24
26
  "fast-deep-equal": "3.1.3"