We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d8192aa commit c977d89Copy full SHA for c977d89
packages/lib/src/equals/shallowEquals.ts
@@ -1,3 +1,20 @@
1
-export const shallowEquals = (a: unknown, b: unknown) => {
2
- return a === b;
3
-};
+export function shallowEquals(objA: unknown, objB: unknown): boolean {
+ if (objA === objB) return true;
+
4
+ if (objA == null || objB == null || typeof objA !== "object" || typeof objB !== "object") {
5
+ return false;
6
+ }
7
8
+ const keysOfA = Object.keys(objA);
9
+ const keysOfB = Object.keys(objB);
10
11
+ if (keysOfA.length !== keysOfB.length) return false;
12
13
+ for (const key of keysOfA) {
14
+ if ((objA as Record<string, unknown>)[key] !== (objB as Record<string, unknown>)[key]) {
15
16
17
18
19
+ return true;
20
+}
0 commit comments