@myshell/angular-select-dropdown
Version:
A angular(4+) select dropdown for single select or multiselect module.
52 lines • 1.97 kB
JavaScript
import { Pipe } from "@angular/core";
/**
* filters an array based on searctext
*/
var ArrayFilterPipe = /** @class */ (function () {
function ArrayFilterPipe() {
}
ArrayFilterPipe.prototype.transform = function (array, searchText, keyName) {
var _this = this;
if (!array || !searchText || !Array.isArray(array)) {
return array;
}
if (typeof array[0] === 'string') {
searchText = searchText.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
return array.filter(function (item) { return _this.exist(item, searchText); });
}
// filter array, items which match and return true will be
// kept, false will be filtered out
if (!keyName) {
return array.filter(function (item) {
for (var key in item) {
if (typeof item[key] !== "object" && _this.exist(item[key].toString(), searchText)) {
return true;
}
}
return false;
});
}
else {
return array.filter(function (item) {
if (typeof item[keyName] !== "object" && _this.exist(item[keyName].toString(), searchText)) {
return true;
}
return false;
});
}
};
ArrayFilterPipe.prototype.exist = function (target, needle) {
target = target.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
return target.indexOf(needle.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "")) > -1;
};
ArrayFilterPipe.decorators = [
{ type: Pipe, args: [{
name: "filterBy"
},] },
];
/** @nocollapse */
ArrayFilterPipe.ctorParameters = function () { return []; };
return ArrayFilterPipe;
}());
export { ArrayFilterPipe };
//# sourceMappingURL=filter-by.pipe.js.map