import { hasOwn } from "./has-own.js";
function deepClone(value) {
  const seen = [];
  return internalDeepClone(value, seen);
}
function internalDeepClone(value, seen) {
  switch (typeof value) {
    case "boolean":
    case "number":
    case "string":
    case "undefined":
      return value;
    case "object": {
      if (value === null) {
        return null;
      }
      if (seen.includes(value)) {
        throw new Error("Cyclic object");
      }
      seen.push(value);
      if (Array.isArray(value)) {
        const rv = value.map((v) => internalDeepClone(v, seen));
        seen.pop();
        return rv;
      }
      const obj = {};
      for (const k in value) {
        if (hasOwn(value, k)) {
          const v = value[k];
          if (v !== void 0) {
            obj[k] = internalDeepClone(v, seen);
          }
        }
      }
      seen.pop();
      return obj;
    }
    default:
      throw new Error(`Invalid type: ${typeof value}`);
  }
}
export {
  deepClone,
  internalDeepClone
};
//# sourceMappingURL=deep-clone.js.map
