UNPKG

@aplus-frontend/ui

Version:

33 lines (32 loc) 749 B
function h(u, f) { if (!u || u.length === 0) throw new Error("No data to transform"); const { targetkeys: n, transfrom: l, mode: p } = f, [a, c] = l; return p === "comp" ? u.map((t) => { if (!c) { const r = n.map((o) => t[o]), e = { ...t }; return n.forEach((o) => delete e[o]), { ...e, [a]: r }; } const s = n.reduce( (r, e, o) => (r[c[o]] = t[e], delete t[e], r), {} ); return { ...t, [a]: s }; }) : u.map((t) => { const s = t[a], r = { ...t }; return delete r[a], Array.isArray(s) ? (n.forEach((e, o) => { r[e] = s[o]; }), r) : (n.forEach((e, o) => { r[e] = s[c[o]]; }), r); }); } export { h as ApTransformDataHelper };