import isObject from './is-object' ; function flatten ( validatorMap , obj , keys , keysUpToFunction = [ ] ) { for ( let key of keys ) { const value = validatorMap [ key ] ; if ( typeof value . validate === 'function' ) { obj [ key ] = value ; } else if ( isObject ( value ) ) { flatten ( value , obj , Object . keys ( value ) , [ ... keysUpToFunction , key ] ) ; } else if ( typeof value === 'function' ) { const dotSeparatedKeys = [ ... keysUpToFunction , key ] . join ( '.' ) ; obj [ dotSeparatedKeys ] = value ; } else if ( Array . isArray ( value ) ) { const isAllFuncs = value . every ( item => typeof item === 'function' || typeof item . validate === 'function' ) ; if ( isAllFuncs ) { const dotSeparatedKeys = [ ... keysUpToFunction , key ] . join ( '.' ) ; obj [ dotSeparatedKeys ] = value ; } } } return obj ; } method return { object } export function flattenValidations ( validatorMap ) { if ( ! validatorMap ) { return { } ; } let obj = { } ; return flatten ( validatorMap , obj , Object . keys ( validatorMap ) ) ; }