/**
-
深度拷贝引用数据(不会复制函数数据)
-
@data [Object, Array]
-
@isDeep Boolean 默认深拷贝
-
#return [Object, Array] */
export function getDeepCopyData(data = {}, isDeep = true){ if(data && typeof data === 'object'){ const obj = data instanceof Array ? [] : {}; for(const [key, value] of Object.entries(data)){ obj[key] = (isDeep && typeof value === 'object') ? getDeepCopyData(value) : value; } return obj; } return data; }
/**
-
深度遍历对象,将对象中所有数组转为指定符号分隔的字符串
-
@obj Object 需要遍历的对象
-
@joinStr String 数组分隔的符号
-
@excludeKeys Array 排除的键名
-
#return Object */
export function walkSplitInObj(obj, excludeKeys = [], joinStr = ','){ if(!obj || typeof obj !== 'object') return obj; return Object.entries(obj).reduce((total, [key, value]) => ({ ...total, [key]: !Array.isArray(value) ? walkSplitInObj(value, excludeKeys, joinStr) : !excludeKeys.includes(key) ? value.join(joinStr) : value }), {}) }