mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
24 lines
438 B
TypeScript
24 lines
438 B
TypeScript
import { isDef } from './index';
|
|
import { ObjectIndex } from './types';
|
|
|
|
export function deepClone(obj: ObjectIndex): object {
|
|
if (!isDef(obj)) {
|
|
return obj;
|
|
}
|
|
|
|
if (Array.isArray(obj)) {
|
|
return obj.map((item) => deepClone(item));
|
|
}
|
|
|
|
if (typeof obj === 'object') {
|
|
const to = {} as ObjectIndex;
|
|
Object.keys(obj).forEach((key) => {
|
|
to[key] = deepClone(obj[key]);
|
|
});
|
|
|
|
return to;
|
|
}
|
|
|
|
return obj;
|
|
}
|