MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / createPredicateFn

Function createPredicateFn

web/static/bower_components/angular/angular.js:18422–18457  ·  view source on GitHub ↗
(expression, comparator, matchAgainstAnyProp)

Source from the content-addressed store, hash-verified

18420
18421// Helper functions for `filterFilter`
18422function createPredicateFn(expression, comparator, matchAgainstAnyProp) {
18423 var shouldMatchPrimitives = isObject(expression) && ('$' in expression);
18424 var predicateFn;
18425
18426 if (comparator === true) {
18427 comparator = equals;
18428 } else if (!isFunction(comparator)) {
18429 comparator = function(actual, expected) {
18430 if (isUndefined(actual)) {
18431 // No substring matching against `undefined`
18432 return false;
18433 }
18434 if ((actual === null) || (expected === null)) {
18435 // No substring matching against `null`; only match against `null`
18436 return actual === expected;
18437 }
18438 if (isObject(expected) || (isObject(actual) && !hasCustomToString(actual))) {
18439 // Should not compare primitives against objects, unless they have custom `toString` method
18440 return false;
18441 }
18442
18443 actual = lowercase('' + actual);
18444 expected = lowercase('' + expected);
18445 return actual.indexOf(expected) !== -1;
18446 };
18447 }
18448
18449 predicateFn = function(item) {
18450 if (shouldMatchPrimitives && !isObject(item)) {
18451 return deepCompare(item, expression.$, comparator, false);
18452 }
18453 return deepCompare(item, expression, comparator, matchAgainstAnyProp);
18454 };
18455
18456 return predicateFn;
18457}
18458
18459function deepCompare(actual, expected, comparator, matchAgainstAnyProp, dontMatchWholeObject) {
18460 var actualType = getTypeForFilter(actual);

Callers 1

filterFilterFunction · 0.85

Calls 6

isObjectFunction · 0.85
isFunctionFunction · 0.85
isUndefinedFunction · 0.85
hasCustomToStringFunction · 0.85
lowercaseFunction · 0.85
deepCompareFunction · 0.85

Tested by

no test coverage detected