@naverpay/hidash
Version:
improved lodash
46 lines (45 loc) • 1.2 kB
JavaScript
import a from "core-js-pure/features/instance/push.js";
import { WEAK_MAP_TAG as p, WEAK_SET_TAG as i, FUNCTION_TAG as u } from "./internal/to-string-tags.mjs";
import { isArray as l } from "./isArray.mjs";
function j(s) {
const f = /* @__PURE__ */ new WeakSet();
function o(t) {
const c = Object.prototype.toString.call(t);
if (c === p || c === i || c === u)
return {};
if (t === null || typeof t != "object")
return t;
if (f.has(t))
return {};
if (f.add(t), l(t)) {
const e = [];
return t.forEach((r) => {
a(e).call(e, o(r));
}), e;
}
if (t instanceof Map) {
const e = /* @__PURE__ */ new Map();
return t.forEach((r, n) => {
e.set(n, o(r));
}), e;
}
if (t instanceof Set) {
const e = /* @__PURE__ */ new Set();
return t.forEach((r) => {
e.add(o(r));
}), e;
}
if (c === "[object Object]") {
const e = Object.getPrototypeOf(t), r = Object.create(e);
for (const n in t)
Object.prototype.hasOwnProperty.call(t, n) && (r[n] = o(t[n]));
return r;
}
return t;
}
return o(s);
}
export {
j as cloneDeep,
j as default
};