@longlast/equals 0.4.0 → 0.4.2
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 +1 -1
- package/dist/index.js +16 -14
- package/package.json +9 -1
- package/dist/curry.d.ts +0 -7
- package/dist/curry.js +0 -12
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module equals
|
|
3
3
|
*/
|
|
4
|
-
import { curry } from "
|
|
4
|
+
import { curry } from "@longlast/curry";
|
|
5
5
|
/**
|
|
6
6
|
* @function
|
|
7
7
|
* Deeply compares two values, returning true if they're equal and false
|
|
@@ -31,6 +31,8 @@ import { curry } from "./curry.js";
|
|
|
31
31
|
*/
|
|
32
32
|
export const equals = curry(_equals);
|
|
33
33
|
function _equals(a, b) {
|
|
34
|
+
// This is an optimized implementation. There is a simpler, equivalent one
|
|
35
|
+
// in pkg/equals/alt/reference.ts.
|
|
34
36
|
if (Object.is(a, b)) {
|
|
35
37
|
return true;
|
|
36
38
|
}
|
|
@@ -45,23 +47,23 @@ function _equals(a, b) {
|
|
|
45
47
|
Object.getPrototypeOf(a) === Object.getPrototypeOf(b));
|
|
46
48
|
}
|
|
47
49
|
if (a instanceof Set && b instanceof Set) {
|
|
48
|
-
return
|
|
50
|
+
return a.size === b.size && [...a].every((v) => b.has(v));
|
|
49
51
|
}
|
|
50
52
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
51
53
|
return a.length === b.length && a.every((_, i) => equals(a[i], b[i]));
|
|
52
54
|
}
|
|
53
|
-
if (
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
if (a && b && typeof a === "object" && protoOf(a) === protoOf(b)) {
|
|
56
|
+
const bKeys = new Set(Object.keys(b));
|
|
57
|
+
for (const key of Object.keys(a)) {
|
|
58
|
+
if (!bKeys.has(key)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (!equals(a[key], b[key])) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
59
66
|
}
|
|
60
67
|
return false;
|
|
61
68
|
}
|
|
62
|
-
|
|
63
|
-
return a.size === b.size && [...a].every((v) => b.has(v));
|
|
64
|
-
}
|
|
65
|
-
function isObject(x) {
|
|
66
|
-
return !!x && typeof x === "object";
|
|
67
|
-
}
|
|
69
|
+
const protoOf = Object.getPrototypeOf;
|
package/package.json
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longlast/equals",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"description": "Deeply compares objects",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Ben Christel (https://benchristel.com/)",
|
|
4
7
|
"type": "module",
|
|
5
8
|
"files": [
|
|
6
9
|
"dist"
|
|
7
10
|
],
|
|
8
11
|
"main": "dist/index.js",
|
|
9
12
|
"types": "dist/index.d.ts",
|
|
13
|
+
"repository": "github:benchristel/longlast",
|
|
14
|
+
"sideEffects": false,
|
|
10
15
|
"imports": {
|
|
11
16
|
"#@longlast/equals": "./src/index.ts"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@longlast/curry": "^0.2.1"
|
|
12
20
|
}
|
|
13
21
|
}
|
package/dist/curry.d.ts
DELETED