diff options
Diffstat (limited to 'shared/core-utils')
-rw-r--r-- | shared/core-utils/common/object.ts | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/shared/core-utils/common/object.ts b/shared/core-utils/common/object.ts index 7f1f147f4..9780b2594 100644 --- a/shared/core-utils/common/object.ts +++ b/shared/core-utils/common/object.ts | |||
@@ -45,10 +45,32 @@ function shallowCopy <T> (o: T): T { | |||
45 | return Object.assign(Object.create(Object.getPrototypeOf(o)), o) | 45 | return Object.assign(Object.create(Object.getPrototypeOf(o)), o) |
46 | } | 46 | } |
47 | 47 | ||
48 | function simpleObjectsDeepEqual (a: any, b: any) { | ||
49 | if (a === b) return true | ||
50 | |||
51 | if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) { | ||
52 | return false | ||
53 | } | ||
54 | |||
55 | const keysA = Object.keys(a) | ||
56 | const keysB = Object.keys(b) | ||
57 | |||
58 | if (keysA.length !== keysB.length) return false | ||
59 | |||
60 | for (const key of keysA) { | ||
61 | if (!keysB.includes(key)) return false | ||
62 | |||
63 | if (!simpleObjectsDeepEqual(a[key], b[key])) return false | ||
64 | } | ||
65 | |||
66 | return true | ||
67 | } | ||
68 | |||
48 | export { | 69 | export { |
49 | pick, | 70 | pick, |
50 | omit, | 71 | omit, |
51 | getKeys, | 72 | getKeys, |
52 | shallowCopy, | 73 | shallowCopy, |
53 | sortObjectComparator | 74 | sortObjectComparator, |
75 | simpleObjectsDeepEqual | ||
54 | } | 76 | } |