import { Pipe , PipeTransform , NgModule } from '@angular/core' ; import { isArray , isDeepObject , unwrapDeep , deepIndexOf } from '../utils/utils' ; @ Pipe ( { name : 'union' , } ) export class UnionPipe implements PipeTransform { transform ( a ? , b ? ) { if ( ( ! isArray ( a ) && ! isDeepObject ( a ) ) || ! isArray ( b ) ) { return [ ] ; } if ( isDeepObject ( a ) ) { const unwrapped = unwrapDeep ( a ) ; if ( ! isArray ( unwrapped ) ) { return [ ] ; } return [ ] . concat ( unwrapped ) . concat ( b ) . filter ( ( value , index , input ) => deepIndexOf ( input , value ) === index ) ; } return [ ] . concat ( a ) . concat ( b ) . filter ( ( value , index , input ) => input . indexOf ( value ) === index ) ; } } @ NgModule ( { declarations : [ UnionPipe ] , exports : [ UnionPipe ] , } ) export class NgUnionPipeModule { }