MCPcopy Create free account
hub / github.com/CommE2E/comm / deepDiff

Function deepDiff

lib/utils/objects.js:78–102  ·  view source on GitHub ↗
(
  obj1: NestedObjectMap<K, T>,
  obj2: NestedObjectMap<K, T>,
)

Source from the content-addressed store, hash-verified

76
77// returns an object with properties from obj1 not included in obj2
78function deepDiff<K, T>(
79 obj1: NestedObjectMap<K, T>,
80 obj2: NestedObjectMap<K, T>,
81): NestedObjectMap<K, T> {
82 let diff: NestedObjectMap<K, T> = {};
83 Object.keys(obj1).forEach((key: K) => {
84 if (_isEqual(obj1[key], obj2[key])) {
85 return;
86 }
87
88 if (!_isPlainObject(obj1[key]) || !_isPlainObject(obj2[key])) {
89 diff = assignValueWithKey(diff, key, obj1[key]);
90 return;
91 }
92
93 const nestedObj1: ObjectMap<K, T> = (obj1[key]: any);
94 const nestedObj2: ObjectMap<K, T> = (obj2[key]: any);
95
96 const nestedDiff = deepDiff(nestedObj1, nestedObj2);
97 if (Object.keys(nestedDiff).length > 0) {
98 diff = assignValueWithKey(diff, key, nestedDiff);
99 }
100 });
101 return diff;
102}
103
104function assertObjectsAreEqual<K, T>(
105 processedObject: ObjectMap<K, T>,

Callers 4

validateRolePermissionsFunction · 0.90
objects.test.jsFile · 0.90
assertObjectsAreEqualFunction · 0.85

Calls 3

assignValueWithKeyFunction · 0.85
forEachMethod · 0.65
keysMethod · 0.65

Tested by

no test coverage detected