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

Function deepCompare

test/angular/1.4/angular.js:18872–18919  ·  view source on GitHub ↗
(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject)

Source from the content-addressed store, hash-verified

18870}
18871
18872function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) {
18873 var actualType = getTypeForFilter(actual);
18874 var expectedType = getTypeForFilter(expected);
18875
18876 if ((expectedType === 'string') && (expected.charAt(0) === '!')) {
18877 return !deepCompare(actual, expected.substring(1), comparator, matchAgainstAnyProp);
18878 } else if (isArray(actual)) {
18879 // In case `actual` is an array, consider it a match
18880 // if ANY of it's items matches `expected`
18881 return actual.some(function(item) {
18882 return deepCompare(item, expected, comparator, matchAgainstAnyProp);
18883 });
18884 }
18885
18886 switch (actualType) {
18887 case 'object':
18888 var key;
18889 if (matchAgainstAnyProp) {
18890 for (key in actual) {
18891 if ((key.charAt(0) !== '$') && deepCompare(actual[key], expected, comparator, true)) {
18892 return true;
18893 }
18894 }
18895 return dontMatchWholeObject ? false : deepCompare(actual, expected, comparator, false);
18896 } else if (expectedType === 'object') {
18897 for (key in expected) {
18898 var expectedVal = expected[key];
18899 if (isFunction(expectedVal) || isUndefined(expectedVal)) {
18900 continue;
18901 }
18902
18903 var matchAnyProperty = key === '$';
18904 var actualVal = matchAnyProperty ? actual : actual[key];
18905 if (!deepCompare(actualVal, expectedVal, comparator, matchAnyProperty, matchAnyProperty)) {
18906 return false;
18907 }
18908 }
18909 return true;
18910 } else {
18911 return comparator(actual, expected);
18912 }
18913 break;
18914 case 'function':
18915 return false;
18916 default:
18917 return comparator(actual, expected);
18918 }
18919}
18920
18921// Used for easily differentiating between `null` and actual `object`
18922function getTypeForFilter(val) {

Callers 1

createPredicateFnFunction · 0.70

Calls 5

isArrayFunction · 0.85
getTypeForFilterFunction · 0.70
isFunctionFunction · 0.70
isUndefinedFunction · 0.70
comparatorFunction · 0.50

Tested by

no test coverage detected