MCPcopy
hub / github.com/angular-ui/ui-router / createPredicateFn

Function createPredicateFn

test/angular/1.4/angular.js:18835–18870  ·  view source on GitHub ↗
(expression, comparator, matchAgainstAnyProp)

Source from the content-addressed store, hash-verified

18833
18834// Helper functions for `filterFilter`
18835function createPredicateFn(expression, comparator, matchAgainstAnyProp) {
18836 var shouldMatchPrimitives = isObject(expression) && ('$' in expression);
18837 var predicateFn;
18838
18839 if (comparator === true) {
18840 comparator = equals;
18841 } else if (!isFunction(comparator)) {
18842 comparator = function(actual, expected) {
18843 if (isUndefined(actual)) {
18844 // No substring matching against `undefined`
18845 return false;
18846 }
18847 if ((actual === null) || (expected === null)) {
18848 // No substring matching against `null`; only match against `null`
18849 return actual === expected;
18850 }
18851 if (isObject(expected) || (isObject(actual) && !hasCustomToString(actual))) {
18852 // Should not compare primitives against objects, unless they have custom `toString` method
18853 return false;
18854 }
18855
18856 actual = lowercase('' + actual);
18857 expected = lowercase('' + expected);
18858 return actual.indexOf(expected) !== -1;
18859 };
18860 }
18861
18862 predicateFn = function(item) {
18863 if (shouldMatchPrimitives && !isObject(item)) {
18864 return deepCompare(item, expression.$, comparator, false);
18865 }
18866 return deepCompare(item, expression, comparator, matchAgainstAnyProp);
18867 };
18868
18869 return predicateFn;
18870}
18871
18872function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) {
18873 var actualType = getTypeForFilter(actual);

Callers 1

filterFilterFunction · 0.70

Calls 6

isObjectFunction · 0.70
isFunctionFunction · 0.70
isUndefinedFunction · 0.70
hasCustomToStringFunction · 0.70
lowercaseFunction · 0.70
deepCompareFunction · 0.70

Tested by

no test coverage detected