import extend from 'extend' ; import type { NzSafeAny } from 'ng-zorro-antd/core/types' ; /**
 * Gets the value at `path` of `object`, like `_.get` in lodash.
 *
 * 类似 `_.get`，根据 `path` 获取安全值
 */ export function deepGet ( obj , path , defaultValue ? ) { if ( ! obj || path == null || path . length === 0 ) return defaultValue ; if ( ! Array . isArray ( path ) ) { path = ~ path . indexOf ( '.' ) ? path . split ( '.' ) : [ path ] ; } if ( path . length === 1 ) { const checkObj = obj [ path [ 0 ] ] ; return typeof checkObj === 'undefined' ? defaultValue : checkObj ; } const res = path . reduce ( ( o , k ) => ( o || { } ) [ k ] , obj ) ; return typeof res === 'undefined' ? defaultValue : res ; } /**
 * Base on [extend](https://github.com/justmoon/node-extend) deep copy.
 *
 * 基于 [extend](https://github.com/justmoon/node-extend) 的深度拷贝
 */ export function deepCopy < T extends { [ key ] : NzSafeAny ; } = NzSafeAny > ( obj ) { const result = extend ( true , { } , { _ : obj } ) ; return result . _ as T ; } param original param arrayProcessMethod param objects export function deepMergeKey ( original , arrayProcessMethod , ... objects ) { if ( Array . isArray ( original ) || typeof original !== 'object' ) return original ; const isObject = ( v ) : boolean => typeof v === 'object' ; const merge = ( target , obj ) : NzSafeAny => { Object . keys ( obj ) . filter ( key => key !== '__proto__' && Object . prototype . hasOwnProperty . call ( obj , key ) ) . forEach ( key => { const fromValue = obj [ key ] ; const toValue = target [ key ] ; if ( Array . isArray ( toValue ) ) { target [ key ] = arrayProcessMethod ? fromValue : [ ... toValue , ... fromValue ] ; } else if ( typeof fromValue === 'function' ) { target [ key ] = fromValue ; } else if ( fromValue != null && isObject ( fromValue ) && toValue != null && isObject ( toValue ) ) { target [ key ] = merge ( toValue , fromValue ) ; } else { target [ key ] = deepCopy ( fromValue ) ; } } ) ; return target ; } ; objects . filter ( v => v != null && isObject ( v ) ) . forEach ( v => merge ( original , v ) ) ; return original ; } /**
 * Deep merge object.
 *
 * 深度合并对象
 */ export function deepMerge ( original , ... objects ) { return deepMergeKey ( original , false , ... objects ) ; }