@longlast/equals 0.5.6 → 0.5.7

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
@@ -18,6 +18,9 @@ import { type Curried2 } from "@longlast/curry";
18
18
  * elements are equal (according to `equals`).
19
19
  * - Sets are equal iff they contain the same elements. Note that set
20
20
  * elements are _not_ deeply compared.
21
+ * - Maps are equal iff they have the same set of keys, and their
22
+ * corresponding values are deeply equal. Note that map keys are _not_
23
+ * deeply compared.
21
24
  * - Partially applied curried functions are equal iff they originate from
22
25
  * the same curried function and their bound arguments are equal
23
26
  * according to `equals`. See {@link curry}.
package/dist/index.js CHANGED
@@ -21,6 +21,9 @@ import { $boundArguments, $equals, $getBoundArguments, $unapplied, } from "@long
21
21
  * elements are equal (according to `equals`).
22
22
  * - Sets are equal iff they contain the same elements. Note that set
23
23
  * elements are _not_ deeply compared.
24
+ * - Maps are equal iff they have the same set of keys, and their
25
+ * corresponding values are deeply equal. Note that map keys are _not_
26
+ * deeply compared.
24
27
  * - Partially applied curried functions are equal iff they originate from
25
28
  * the same curried function and their bound arguments are equal
26
29
  * according to `equals`. See {@link curry}.
@@ -121,7 +124,19 @@ function _equals(a, b) {
121
124
  return a.size === b.size && [...a].every((v) => b.has(v));
122
125
  }
123
126
  // TODO: typed arrays
124
- // TODO: Map
127
+ if (mapConstructorString === aConstructorString) {
128
+ unsafeNarrow(a);
129
+ unsafeNarrow(b);
130
+ if (a.size !== b.size) {
131
+ return false;
132
+ }
133
+ for (const key of a.keys()) {
134
+ if (!b.has(key) || !_equals(a.get(key), b.get(key))) {
135
+ return false;
136
+ }
137
+ }
138
+ return true;
139
+ }
125
140
  if (objectConstructorString === aConstructorString ||
126
141
  protoOf(a) === protoOf(b)) {
127
142
  unsafeNarrow(a);
@@ -168,6 +183,7 @@ const objectConstructorString = functionString(Object);
168
183
  const dateConstructorString = functionString(Date);
169
184
  const regexConstructorString = functionString(RegExp);
170
185
  const setConstructorString = functionString(Set);
186
+ const mapConstructorString = functionString(Map);
171
187
  const nativeErrorConstructorStrings = [
172
188
  functionString(Error),
173
189
  // TODO: add DOMException? Be sure to check the `name` property.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longlast/equals",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "Deeply compares objects",
5
5
  "homepage": "https://longlast.js.org/",
6
6
  "license": "MIT",