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

Function deepCompare

lib/test/angular/1.4.3/angular.js:18319–18366  ·  view source on GitHub ↗
(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject)

Source from the content-addressed store, hash-verified

18317}
18318
18319function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) {
18320 var actualType = getTypeForFilter(actual);
18321 var expectedType = getTypeForFilter(expected);
18322
18323 if ((expectedType === 'string') && (expected.charAt(0) === '!')) {
18324 return !deepCompare(actual, expected.substring(1), comparator, matchAgainstAnyProp);
18325 } else if (isArray(actual)) {
18326 // In case `actual` is an array, consider it a match
18327 // if ANY of it's items matches `expected`
18328 return actual.some(function(item) {
18329 return deepCompare(item, expected, comparator, matchAgainstAnyProp);
18330 });
18331 }
18332
18333 switch (actualType) {
18334 case 'object':
18335 var key;
18336 if (matchAgainstAnyProp) {
18337 for (key in actual) {
18338 if ((key.charAt(0) !== '$') && deepCompare(actual[key], expected, comparator, true)) {
18339 return true;
18340 }
18341 }
18342 return dontMatchWholeObject ? false : deepCompare(actual, expected, comparator, false);
18343 } else if (expectedType === 'object') {
18344 for (key in expected) {
18345 var expectedVal = expected[key];
18346 if (isFunction(expectedVal) || isUndefined(expectedVal)) {
18347 continue;
18348 }
18349
18350 var matchAnyProperty = key === '$';
18351 var actualVal = matchAnyProperty ? actual : actual[key];
18352 if (!deepCompare(actualVal, expectedVal, comparator, matchAnyProperty, matchAnyProperty)) {
18353 return false;
18354 }
18355 }
18356 return true;
18357 } else {
18358 return comparator(actual, expected);
18359 }
18360 break;
18361 case 'function':
18362 return false;
18363 default:
18364 return comparator(actual, expected);
18365 }
18366}
18367
18368// Used for easily differentiating between `null` and actual `object`
18369function 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