import { Pipe , PipeTransform , Injectable } from "@angular/core" ; @ Pipe ( { name : 'filter' , pure : false } ) @ Injectable ( ) export class Ng2SearchPipe implements PipeTransform { param items param term param excludes transform ( items , term , excludes = [ ] ) { if ( ! term || ! items ) return items ; return Ng2SearchPipe . filter ( items , term , excludes ) ; } param items param term param excludes static filter ( items , term , excludes ) { const toCompare = term . toLowerCase ( ) ; function checkInside ( item , term ) { if ( typeof item === "string" && item . toString ( ) . toLowerCase ( ) . includes ( toCompare ) ) { return true ; } for ( let property in item ) { if ( item [ property ] === null || item [ property ] == undefined || excludes . includes ( property ) ) { continue ; } if ( typeof item [ property ] === 'object' ) { if ( checkInside ( item [ property ] , term ) ) { return true ; } } else if ( item [ property ] . toString ( ) . toLowerCase ( ) . includes ( toCompare ) ) { return true ; } } return false ; } return items . filter ( function ( item ) { return checkInside ( item , term ) ; } ) ; } }