@longlast/equals 0.5.5 → 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 +3 -0
- package/dist/index.js +21 -4
- package/package.json +4 -1
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}.
|
|
@@ -105,13 +108,14 @@ function _equals(a, b) {
|
|
|
105
108
|
if (regexConstructorString === aConstructorString) {
|
|
106
109
|
return String(a) === String(b);
|
|
107
110
|
}
|
|
108
|
-
if (
|
|
111
|
+
if (a instanceof Error ||
|
|
109
112
|
nativeErrorConstructorStrings.includes(aConstructorString)) {
|
|
110
113
|
unsafeNarrow(a);
|
|
111
114
|
unsafeNarrow(b);
|
|
112
115
|
return a.message === b.message;
|
|
113
116
|
}
|
|
114
|
-
if (Array.isArray(a)
|
|
117
|
+
if (Array.isArray(a)) {
|
|
118
|
+
unsafeNarrow(b);
|
|
115
119
|
return a.length === b.length && a.every((_, i) => _equals(a[i], b[i]));
|
|
116
120
|
}
|
|
117
121
|
if (setConstructorString === aConstructorString) {
|
|
@@ -120,7 +124,19 @@ function _equals(a, b) {
|
|
|
120
124
|
return a.size === b.size && [...a].every((v) => b.has(v));
|
|
121
125
|
}
|
|
122
126
|
// TODO: typed arrays
|
|
123
|
-
|
|
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
|
+
}
|
|
124
140
|
if (objectConstructorString === aConstructorString ||
|
|
125
141
|
protoOf(a) === protoOf(b)) {
|
|
126
142
|
unsafeNarrow(a);
|
|
@@ -157,7 +173,7 @@ function constructorOf(value) {
|
|
|
157
173
|
if (value == null) {
|
|
158
174
|
return null;
|
|
159
175
|
}
|
|
160
|
-
return
|
|
176
|
+
return protoOf(value)?.constructor;
|
|
161
177
|
}
|
|
162
178
|
function unsafeNarrow(value) {
|
|
163
179
|
value;
|
|
@@ -167,6 +183,7 @@ const objectConstructorString = functionString(Object);
|
|
|
167
183
|
const dateConstructorString = functionString(Date);
|
|
168
184
|
const regexConstructorString = functionString(RegExp);
|
|
169
185
|
const setConstructorString = functionString(Set);
|
|
186
|
+
const mapConstructorString = functionString(Map);
|
|
170
187
|
const nativeErrorConstructorStrings = [
|
|
171
188
|
functionString(Error),
|
|
172
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.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "Deeply compares objects",
|
|
5
5
|
"homepage": "https://longlast.js.org/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,5 +19,8 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@longlast/curry": "^0.5.0",
|
|
21
21
|
"@longlast/symbols": "^1.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"fast-deep-equal": "3.1.3"
|
|
22
25
|
}
|
|
23
26
|
}
|