mirror of
https://github.com/CamHenlin/MessagesForMacintosh.git
synced 2024-12-12 00:29:07 +00:00
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var toString = Object.prototype.toString;
|
|
function cloneDeep(value) {
|
|
return cloneDeepHelper(value, new Map());
|
|
}
|
|
exports.cloneDeep = cloneDeep;
|
|
function cloneDeepHelper(val, seen) {
|
|
switch (toString.call(val)) {
|
|
case "[object Array]": {
|
|
if (seen.has(val))
|
|
return seen.get(val);
|
|
var copy_1 = val.slice(0);
|
|
seen.set(val, copy_1);
|
|
copy_1.forEach(function (child, i) {
|
|
copy_1[i] = cloneDeepHelper(child, seen);
|
|
});
|
|
return copy_1;
|
|
}
|
|
case "[object Object]": {
|
|
if (seen.has(val))
|
|
return seen.get(val);
|
|
var copy_2 = Object.create(Object.getPrototypeOf(val));
|
|
seen.set(val, copy_2);
|
|
Object.keys(val).forEach(function (key) {
|
|
copy_2[key] = cloneDeepHelper(val[key], seen);
|
|
});
|
|
return copy_2;
|
|
}
|
|
default:
|
|
return val;
|
|
}
|
|
}
|
|
//# sourceMappingURL=cloneDeep.js.map
|