st-common-core
Version:
小尾巴前端通用核心库
67 lines (66 loc) • 1.63 kB
JavaScript
import { copyDeep as w } from "../../arr/utils/arr-copy-util.js";
const H = (l, t, u, c, n) => {
if (Reflect.has(n, c)) {
const s = n[c];
return s(l, t, c);
} else
return u;
}, z = ({
origin: l,
props: t = [],
excludeProps: u = [],
propsMap: c = {},
targetPropValMap: n = {},
excludeArrItem: s = () => !1,
sort: T = null,
isCopyEmptyArr: D = !0,
isRemoveObjUndefined: k = !1,
isRemoveArrUndefined: $ = !1
}) => {
const h = {};
for (const f in l) {
if (u.length > 0 && u.includes(f) || t.length > 0 && !t.includes(f)) continue;
let e = null;
if (l[f] === void 0) {
if (k) continue;
e = l[f];
} else if (l[f] === null || typeof l[f] == "function")
e = l[f];
else if (Array.isArray(l[f])) {
if (e = w({
origin: l[f],
props: t,
excludeProps: u,
propsMap: c,
targetPropValMap: n,
excludeArrItem: s,
sort: T,
isCopyEmptyArr: D,
isRemoveObjUndefined: k,
isRemoveArrUndefined: $
}), e.length === 0 && !D) continue;
} else typeof l[f] == "object" ? e = z({
origin: l[f],
props: t,
excludeProps: u,
propsMap: c,
targetPropValMap: n,
excludeArrItem: s,
sort: T,
isCopyEmptyArr: D,
isRemoveObjUndefined: k,
isRemoveArrUndefined: $
}) : e = l[f];
if (Reflect.has(c, f)) {
const y = c[f];
Array.isArray(y) ? y.forEach((q) => {
h[q] = H(l, f, e, q, n);
}) : h[y] = H(l, f, e, y, n);
} else
h[f] = H(l, f, e, f, n);
}
return h;
};
export {
z as copyDeep
};