import * as T from "./types" ; import { isArray , push , isNil } from "./utils" ; import { compose } from "./compose" ; export function filter < P extends T . Props > ( options ) { const { propsKeys , renderers , reducer , initial } = options ; const keys = [ ] ; if ( isArray ( propsKeys ) ) { push . apply ( keys , propsKeys ) ; } if ( isArray ( renderers ) ) { const filterSet = compose ( { name : "filter" , renderers } ) ; push . apply ( keys , filterSet . options . propsKeys ) ; } const filterProps = ( props ) => { return keys . reduce ( ( acc , key ) => { return reducer ( acc , key , props ) ; } , initial ( props ) ) ; } ; return filterProps ; } export function omit < P extends T . Props > ( options ) { return filter ( { propsKeys : options . propsKeys , renderers : options . renderers , initial : ( props ) => Object . assign ( { } , props ) , reducer : ( acc , key ) => { delete acc [ key ] ; return acc ; } } ) ; } export function pick < P extends T . Props > ( options ) { return filter ( { propsKeys : options . propsKeys , renderers : options . renderers , initial : ( ) => ( { } ) , reducer : ( acc , key , props ) => { const value = props [ key ] ; if ( ! isNil ( value ) ) acc [ key ] = value ; return acc ; } } ) ; }