4cd4fd28
郭伟龙
feat: 初始化项目
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import { isArray, isPlainObject } from './inspect'
import { keys } from './object'
export const cloneDeep = (obj, defaultValue = obj) => {
if (isArray(obj)) {
return obj.reduce((result, val) => [...result, cloneDeep(val, val)], [])
}
if (isPlainObject(obj)) {
return keys(obj).reduce(
(result, key) => ({ ...result, [key]: cloneDeep(obj[key], obj[key]) }),
{}
)
}
return defaultValue
}
|