]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/core-utils/common/object.ts
Allow to update a live with untouched privacy
[github/Chocobozzz/PeerTube.git] / shared / core-utils / common / object.ts
index 7f1f147f4b3870f49680db9f7cfc0a991e54b758..9780b2594327af1b0113dd1e6ae574300e74d7da 100644 (file)
@@ -45,10 +45,32 @@ function shallowCopy <T> (o: T): T {
   return Object.assign(Object.create(Object.getPrototypeOf(o)), o)
 }
 
+function simpleObjectsDeepEqual (a: any, b: any) {
+  if (a === b) return true
+
+  if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {
+    return false
+  }
+
+  const keysA = Object.keys(a)
+  const keysB = Object.keys(b)
+
+  if (keysA.length !== keysB.length) return false
+
+  for (const key of keysA) {
+    if (!keysB.includes(key)) return false
+
+    if (!simpleObjectsDeepEqual(a[key], b[key])) return false
+  }
+
+  return true
+}
+
 export {
   pick,
   omit,
   getKeys,
   shallowCopy,
-  sortObjectComparator
+  sortObjectComparator,
+  simpleObjectsDeepEqual
 }