@naverpay/hidash
Version:
improved lodash
66 lines (65 loc) • 1.51 kB
JavaScript
import { DATE_TAG as y, REGEXP_TAG as u } from "./internal/to-string-tags.mjs";
import { isNil as v } from "./isNil.mjs";
import { isObject as s } from "./isObject.mjs";
const m = Object.prototype.toString, A = m.call.bind(m);
function h(n, e) {
return e === y ? new Date(n) : new RegExp(n);
}
function c(n, e) {
if (e == null)
return n;
const f = A(e);
if (f === y || f === u)
return h(e, f);
if (Array.isArray(e)) {
if (!Array.isArray(n))
return e.slice();
const r = e.length;
n.length < r && (n.length = r);
for (let t = 0; t < r; t++)
if (t in e) {
const i = e[t];
if (i == null) {
n[t] = i;
continue;
}
const l = A(i);
n[t] = l === y || l === u ? h(i, l) : s(i) ? c(s(n[t]) ? n[t] : {}, i) : i;
}
return n;
}
if (s(e)) {
const o = Object.keys(e), r = o.length;
let t;
for (let i = 0; i < r; i++) {
t = o[i];
const l = e[t];
if (l !== void 0)
if (l !== null && typeof l == "object") {
const p = A(l);
if (p === y || p === u)
n[t] = h(l, p);
else {
const T = n[t];
n[t] = s(T) ? c(T, l) : c({}, l);
}
} else
n[t] = l;
}
return n;
}
return e;
}
function g(n, ...e) {
const f = e.length;
if (!f)
return v(n) ? {} : n;
let o = n;
for (let r = 0; r < f; r++)
o = c(o, e[r]);
return o;
}
export {
g as default,
g as merge
};