import { isPlainObject , isString } from './is' ; export function deepMerge < T = any > ( ... objs ) { const result = { } ; objs . forEach ( ( obj ) => Object . keys ( obj ) . forEach ( ( key ) => { const val = obj [ key ] ; const resultVal = result [ key ] ; if ( isPlainObject ( resultVal ) && isPlainObject ( val ) ) { result [ key ] = deepMerge ( resultVal , val ) ; } else if ( isPlainObject ( val ) ) { result [ key ] = deepMerge ( val ) ; } else { result [ key ] = val ; } } ) ) ; return result as T ; } export function pick < T extends AnyObject , K extends keyof T > ( obj , ... keys ) { const _pick = { } ; keys . forEach ( ( key ) => ( _pick [ key ] = obj [ key ] ) ) ; return _pick as Pick < T , K > ; } export function omit < T extends AnyObject , K extends keyof T > ( obj , ... keys ) { const _omit = Object . assign ( { } , obj ) ; keys . forEach ( ( key ) => delete _omit [ key ] ) ; return _omit ; } export function assert ( condition , msg ) { if ( ! condition ) { throwError ( msg ) ; } } export function throwError ( msg ) { throw new Error ( `[axios-miniprogram]: ${ msg }` ) ; } export function toLowerCase < T extends string > ( value , defaultValue ) { if ( ! isString ( value ) ) { value = defaultValue ; } return value . toLowerCase ( ) as T ; } export function toUpperCase < T extends string > ( value , defaultValue ) { if ( ! isString ( value ) ) { value = defaultValue ; } return value . toUpperCase ( ) as T ; }