import { isPlainObject } from "./isPlainObject" ; /**
 * Recursively merge 2 Objects together.  Will resolve functions if they are present, unless the parent Object has the property `_toExpand = false`.
 * Actionhero uses this internally to construct and resolve the config.
 * Matching keys in B override A.
 */ export function hashMerge ( a , b , arg ? ) { const c = { } ; let i ; let response ; for ( i in a ) { if ( isPlainObject ( a [ i ] ) ) { c [ i ] = Object . keys ( a [ i ] ) . length > 0 ? hashMerge ( c [ i ] , a [ i ] , arg ) : { } ; } else { if ( typeof a [ i ] === "function" ) { response = a [ i ] ( arg ) ; if ( isPlainObject ( response ) ) { c [ i ] = hashMerge ( c [ i ] , response , arg ) ; } else { c [ i ] = response ; } } else { if ( a [ i ] === undefined || a [ i ] === null ) { } else c [ i ] = a [ i ] ; } } } for ( i in b ) { if ( isPlainObject ( b [ i ] ) ) { if ( Object . keys ( b [ i ] ) . length > 0 ) c [ i ] = hashMerge ( c [ i ] , b [ i ] , arg ) ; else if ( ! ( i in c ) ) c [ i ] = { } ; } else { if ( typeof b [ i ] === "function" ) { response = b [ i ] ( arg ) ; if ( isPlainObject ( response ) ) { c [ i ] = hashMerge ( c [ i ] , response , arg ) ; } else { c [ i ] = response ; } } else { if ( b [ i ] === undefined ) { } else if ( b [ i ] == null && i in c ) delete c [ i ] ; else c [ i ] = b [ i ] ; } } } return c ; }