MCPcopy Create free account
hub / github.com/apache/cloudstack / filterFilter

Function filterFilter

tools/ngui/static/js/lib/angular.js:9701–9782  ·  view source on GitHub ↗

* @ngdoc filter * @name ng.filter:filter * @function * * @description * Selects a subset of items from `array` and returns it as a new array. * * Note: This function is used to augment the `Array` type in Angular expressions. See * ng.$filter for more information about Angular arrays

()

Source from the content-addressed store, hash-verified

9699 </doc:example>
9700 */
9701function filterFilter() {
9702 return function(array, expression) {
9703 if (!isArray(array)) return array;
9704 var predicates = [];
9705 predicates.check = function(value) {
9706 for (var j = 0; j < predicates.length; j++) {
9707 if(!predicates[j](value)) {
9708 return false;
9709 }
9710 }
9711 return true;
9712 };
9713 var search = function(obj, text){
9714 if (text.charAt(0) === '!') {
9715 return !search(obj, text.substr(1));
9716 }
9717 switch (typeof obj) {
9718 case "boolean":
9719 case "number":
9720 case "string":
9721 return ('' + obj).toLowerCase().indexOf(text) > -1;
9722 case "object":
9723 for ( var objKey in obj) {
9724 if (objKey.charAt(0) !== '$' && search(obj[objKey], text)) {
9725 return true;
9726 }
9727 }
9728 return false;
9729 case "array":
9730 for ( var i = 0; i < obj.length; i++) {
9731 if (search(obj[i], text)) {
9732 return true;
9733 }
9734 }
9735 return false;
9736 default:
9737 return false;
9738 }
9739 };
9740 switch (typeof expression) {
9741 case "boolean":
9742 case "number":
9743 case "string":
9744 expression = {$:expression};
9745 case "object":
9746 for (var key in expression) {
9747 if (key == '$') {
9748 (function() {
9749 var text = (''+expression[key]).toLowerCase();
9750 if (!text) return;
9751 predicates.push(function(value) {
9752 return search(value, text);
9753 });
9754 })();
9755 } else {
9756 (function() {
9757 var path = key;
9758 var text = (''+expression[key]).toLowerCase();

Callers

nothing calls this directly

Calls 4

isArrayFunction · 0.85
searchFunction · 0.85
getterFunction · 0.85
checkMethod · 0.65

Tested by

no test coverage detected