UNPKG

@aplus-frontend/ui

Version:

19 lines (18 loc) 402 B
const u = { parentKey: "parentId", key: "id", children: "children" }; function y(c, s = {}) { const n = Object.assign(s, u), i = n.parentKey, l = n.key, t = n.children, r = []; function o(d, p = null) { for (const a of d) { const e = { ...a }; e[i] = p, r.push(e), e[t]?.length && o(e[t], e[l]), delete e[t]; } } return o(c, null), r; } export { y as toTreeArray };