21 lines
379 B
JavaScript
21 lines
379 B
JavaScript
import { isDef, isObject } from "./basic.mjs";
|
|
function deepClone(obj) {
|
|
if (!isDef(obj)) {
|
|
return obj;
|
|
}
|
|
if (Array.isArray(obj)) {
|
|
return obj.map((item) => deepClone(item));
|
|
}
|
|
if (isObject(obj)) {
|
|
const to = {};
|
|
Object.keys(obj).forEach((key) => {
|
|
to[key] = deepClone(obj[key]);
|
|
});
|
|
return to;
|
|
}
|
|
return obj;
|
|
}
|
|
export {
|
|
deepClone
|
|
};
|