fwk-pipes
Version:
Framework with common pipes
37 lines • 1.27 kB
JavaScript
import { Pipe } from '@angular/core';
var SearchObjectPipe = (function () {
function SearchObjectPipe() {
}
SearchObjectPipe.prototype.transform = function (arr, txt, fields, minLen, all) {
console.log('searchObject: arr.length:' + arr.length + ' / txt:' + txt + ' / all:' + JSON.stringify(all));
if ((!arr))
return [];
if (!txt)
return (!all) ? [] : arr;
if (!minLen)
minLen = 1;
if (txt.length < minLen)
return (!all) ? [] : arr;
console.log('searchObject proceed to filter');
var res = arr.filter(function (item) {
var found = false;
fields.forEach(function (field) {
if (item[field]) {
var str = item[field].toLowerCase();
if (str.indexOf(txt.toLowerCase()) > -1) {
found = true;
return;
}
}
});
return found;
});
return res;
};
SearchObjectPipe.decorators = [
{ type: Pipe, args: [{ name: 'searchObject' },] },
];
return SearchObjectPipe;
}());
export { SearchObjectPipe };
//# sourceMappingURL=searchObject.pipe.js.map