MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / deepCompare

Function deepCompare

lib/test/angular/1.5.0/angular.js:19348–19395  ·  view source on GitHub ↗
(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject)

Source from the content-addressed store, hash-verified

19346}
19347
19348function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) {
19349 var actualType = getTypeForFilter(actual);
19350 var expectedType = getTypeForFilter(expected);
19351
19352 if ((expectedType === 'string') && (expected.charAt(0) === '!')) {
19353 return !deepCompare(actual, expected.substring(1), comparator, matchAgainstAnyProp);
19354 } else if (isArray(actual)) {
19355 // In case `actual` is an array, consider it a match
19356 // if ANY of it's items matches `expected`
19357 return actual.some(function(item) {
19358 return deepCompare(item, expected, comparator, matchAgainstAnyProp);
19359 });
19360 }
19361
19362 switch (actualType) {
19363 case 'object':
19364 var key;
19365 if (matchAgainstAnyProp) {
19366 for (key in actual) {
19367 if ((key.charAt(0) !== '$') && deepCompare(actual[key], expected, comparator, true)) {
19368 return true;
19369 }
19370 }
19371 return dontMatchWholeObject ? false : deepCompare(actual, expected, comparator, false);
19372 } else if (expectedType === 'object') {
19373 for (key in expected) {
19374 var expectedVal = expected[key];
19375 if (isFunction(expectedVal) || isUndefined(expectedVal)) {
19376 continue;
19377 }
19378
19379 var matchAnyProperty = key === '$';
19380 var actualVal = matchAnyProperty ? actual : actual[key];
19381 if (!deepCompare(actualVal, expectedVal, comparator, matchAnyProperty, matchAnyProperty)) {
19382 return false;
19383 }
19384 }
19385 return true;
19386 } else {
19387 return comparator(actual, expected);
19388 }
19389 break;
19390 case 'function':
19391 return false;
19392 default:
19393 return comparator(actual, expected);
19394 }
19395}
19396
19397// Used for easily differentiating between `null` and actual `object`
19398function getTypeForFilter(val) {

Callers 1

createPredicateFnFunction · 0.70

Calls 4

getTypeForFilterFunction · 0.70
isFunctionFunction · 0.70
isUndefinedFunction · 0.70
isArrayFunction · 0.50

Tested by

no test coverage detected