"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cloneDeep = cloneDeep;
const { toString } = Object.prototype;
/**
 * Deeply clones a value to create a new instance.
 */
function cloneDeep(value) {
    return cloneDeepHelper(value);
}
function cloneDeepHelper(val, seen) {
    switch (toString.call(val)) {
        case "[object Array]": {
            seen = seen || new Map();
            if (seen.has(val))
                return seen.get(val);
            const copy = val.slice(0);
            seen.set(val, copy);
            copy.forEach(function (child, i) {
                copy[i] = cloneDeepHelper(child, seen);
            });
            return copy;
        }
        case "[object Object]": {
            seen = seen || new Map();
            if (seen.has(val))
                return seen.get(val);
            // High fidelity polyfills of Object.create and Object.getPrototypeOf are
            // possible in all JS environments, so we will assume they exist/work.
            const copy = Object.create(Object.getPrototypeOf(val));
            seen.set(val, copy);
            Object.keys(val).forEach((key) => {
                copy[key] = cloneDeepHelper(val[key], seen);
            });
            return copy;
        }
        default:
            return val;
    }
}
//# sourceMappingURL=cloneDeep.cjs.map
