import { Pipe , PipeTransform , NgModule } from '@angular/core' ; import { isArray , isDeepObject , unwrapDeep , deepIndexOf } from '../utils/utils' ; @ Pipe ( { name : 'uniq' , } ) export class UniqPipe implements PipeTransform { transform ( input ) { if ( ! isArray ( input ) && ! isDeepObject ( input ) ) { return input ; } if ( isDeepObject ( input ) ) { const unwrappedInput = unwrapDeep ( input ) ; if ( ! isArray ( unwrappedInput ) ) { return unwrappedInput ; } return unwrappedInput . filter ( ( value , index ) => deepIndexOf ( unwrappedInput , value ) === index ) ; } return input . filter ( ( value , index ) => input . indexOf ( value ) === index ) ; } } @ NgModule ( { declarations : [ UniqPipe ] , exports : [ UniqPipe ] , } ) export class NgUniqPipeModule { }