summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pipes/searchFilter.pipe.ts
blob: 3a0c85dda2c54a8a37038faeb50dedac61576ac3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'searchFilter',
})
export class SearchFilterPipe implements PipeTransform {
    public transform(value, key: string, term: string) {
        if (!term || !term.length) return value;
        return value.filter((item) => {
            if (item.hasOwnProperty(key)) {
                return item[key].indexOf(term) > -1;
            } else {
                return false;
            }
        });
    }
}