diff --git a/.circleci/config.yml b/.circleci/config.yml index 2573e3f..dccf0ac 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 jobs: build: docker: - - image: circleci/node:10.12.0 + - image: circleci/node:10.13.0 steps: - checkout diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..227b71f --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +build +coverage \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1 @@ +{} diff --git a/README.md b/README.md index 700082f..0b28652 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ [![Dependency Status](https://david-dm.org/philipstanislaus/performant-array-to-tree.svg)](https://david-dm.org/philipstanislaus/performant-array-to-tree) [![devDependency Status](https://david-dm.org/philipstanislaus/performant-array-to-tree/dev-status.svg)](https://david-dm.org/philipstanislaus/performant-array-to-tree?type=dev) [![typings included](https://img.shields.io/badge/typings-included-brightgreen.svg)](#typescript) -[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![npm license](https://img.shields.io/npm/l/performant-array-to-tree.svg)](https://www.npmjs.com/package/performant-array-to-tree) Converts an array of items with ids and parent ids to a nested tree in a performant way (time complexity `O(n)`). Runs in browsers and node. @@ -33,26 +32,32 @@ or if using npm ```js const tree = arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: null, custom: 'ü'}, -]) + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: null, custom: "ü" }, +]); ``` Which results in the following array: ```js [ - { data: { id: '4', parentId: null, custom: 'abc' }, children: [ - { data: { id: '31', parentId: '4', custom: '12' }, children: [] }, - ] }, - { data: { id: '418', parentId: null, custom: 'ü'}, children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, - ] }, -] + { + data: { id: "4", parentId: null, custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], + }, + { + data: { id: "418", parentId: null, custom: "ü" }, + children: [ + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, + ], + }, +]; ``` ## Configuration @@ -69,72 +74,99 @@ You can provide a second argument to arrayToTree with configuration options. Rig Example: ```js -const tree = arrayToTree([ - { num: '4', ref: null, custom: 'abc' }, - { num: '31', ref: '4', custom: '12' }, - { num: '1941', ref: '418', custom: 'de' }, - { num: '1', ref: '418', custom: 'ZZZz' }, - { num: '418', ref: null, custom: 'ü'}, -], { id: 'num', parentId: 'ref', childrenField: 'nodes' }) +const tree = arrayToTree( + [ + { num: "4", ref: null, custom: "abc" }, + { num: "31", ref: "4", custom: "12" }, + { num: "1941", ref: "418", custom: "de" }, + { num: "1", ref: "418", custom: "ZZZz" }, + { num: "418", ref: null, custom: "ü" }, + ], + { id: "num", parentId: "ref", childrenField: "nodes" } +); ``` Which produces: ```js [ - { data: { num: '4', ref: null, custom: 'abc' }, nodes: [ - { data: { num: '31', ref: '4', custom: '12' }, nodes: [] }, - ] }, - { data: { num: '418', ref: null, custom: 'ü'}, nodes: [ - { data: { num: '1941', ref: '418', custom: 'de' }, nodes: [] }, - { data: { num: '1', ref: '418', custom: 'ZZZz' }, nodes: [] }, - ] }, -] + { + data: { num: "4", ref: null, custom: "abc" }, + nodes: [{ data: { num: "31", ref: "4", custom: "12" }, nodes: [] }], + }, + { + data: { num: "418", ref: null, custom: "ü" }, + nodes: [ + { data: { num: "1941", ref: "418", custom: "de" }, nodes: [] }, + { data: { num: "1", ref: "418", custom: "ZZZz" }, nodes: [] }, + ], + }, +]; ``` Example with no data field: ```js -const tree = arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: null, custom: 'ü'}, -], { dataField: null }) +const tree = arrayToTree( + [ + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: null, custom: "ü" }, + ], + { dataField: null } +); ``` Which produces: ```js [ - { id: '4', parentId: null, custom: 'abc', children: [ - { id: '31', parentId: '4', custom: '12', children: [] }, - ] }, - { id: '418', parentId: null, custom: 'ü', children: [ - { id: '1941', parentId: '418', custom: 'de', children: [] }, - { id: '1', parentId: '418', custom: 'ZZZz', children: [] }, - ] }, -] + { + id: "4", + parentId: null, + custom: "abc", + children: [{ id: "31", parentId: "4", custom: "12", children: [] }], + }, + { + id: "418", + parentId: null, + custom: "ü", + children: [ + { id: "1941", parentId: "418", custom: "de", children: [] }, + { id: "1", parentId: "418", custom: "ZZZz", children: [] }, + ], + }, +]; ``` Example with nested id/parentId properties: ```js -const tree = arrayToTree([ - { num: { id: '4' }, parent: { parentId: null }, custom: 'abc' }, - { num: { id: '31' }, parent: { parentId: '4' }, custom: '12' }, -], { id: 'num.id', parentId: 'parent.parentId' }) +const tree = arrayToTree( + [ + { num: { id: "4" }, parent: { parentId: null }, custom: "abc" }, + { num: { id: "31" }, parent: { parentId: "4" }, custom: "12" }, + ], + { id: "num.id", parentId: "parent.parentId" } +); ``` Which produces: ```js [ - { data: { num: { id: '4' }, parent: { parentId: null }, custom: 'abc' }, children: [ - { data: { num: { id: '31' }, parent: { parentId: '4' }, custom: '12' }, children: [] }, - ] }, -] + { + data: { num: { id: "4" }, parent: { parentId: null }, custom: "abc" }, + children: [ + { + data: { num: { id: "31" }, parent: { parentId: "4" }, custom: "12" }, + children: [], + }, + ], + }, +]; ``` ## TypeScript @@ -142,7 +174,7 @@ Which produces: This project includes types, just import the module as usual: ```ts -import { arrayToTree } from 'performant-array-to-tree' +import { arrayToTree } from "performant-array-to-tree"; -const tree = arrayToTree(array) +const tree = arrayToTree(array); ``` diff --git a/build/arrayToTree.js b/build/arrayToTree.js index 17e5d41..3c054fa 100644 --- a/build/arrayToTree.js +++ b/build/arrayToTree.js @@ -13,12 +13,12 @@ var __assign = (this && this.__assign) || function () { Object.defineProperty(exports, "__esModule", { value: true }); exports.arrayToTree = void 0; var defaultConfig = { - id: 'id', - parentId: 'parentId', - dataField: 'data', - childrenField: 'children', + id: "id", + parentId: "parentId", + dataField: "data", + childrenField: "children", throwIfOrphans: false, - rootParentIds: { '': true }, + rootParentIds: { "": true }, }; /** * Unflattens an array to a tree with runtime O(n) @@ -33,7 +33,9 @@ function arrayToTree(items, config) { var lookup = {}; // stores all item ids that have not been added to the resulting unflattened tree yet // this is an opt-in property, since it has a slight runtime overhead - var orphanIds = config.throwIfOrphans ? new Set() : null; + var orphanIds = config.throwIfOrphans + ? new Set() + : null; // idea of this loop: // whenever an item has a parent, but the parent is not yet in the lookup object, we store a preliminary parent // in the lookup object and fill it with the data of the parent later @@ -44,7 +46,9 @@ function arrayToTree(items, config) { var parentId = getNestedProperty(item, conf.parentId); if (conf.rootParentIds[itemId]) { throw new Error("The item array contains a node whose parentId both exists in another node and is in " + - ("`rootParentIds` (`itemId`: \"" + itemId + "\", `rootParentIds`: " + Object.keys(conf.rootParentIds).map(function (r) { return "\"" + r + "\""; }).join(', ') + ").")); + ("`rootParentIds` (`itemId`: \"" + itemId + "\", `rootParentIds`: " + Object.keys(conf.rootParentIds) + .map(function (r) { return "\"" + r + "\""; }) + .join(", ") + ").")); } // look whether item already exists in the lookup table if (!Object.prototype.hasOwnProperty.call(lookup, itemId)) { @@ -62,10 +66,12 @@ function arrayToTree(items, config) { else { lookup[itemId] = __assign(__assign({}, item), (_b = {}, _b[conf.childrenField] = lookup[itemId][conf.childrenField], _b)); } - var TreeItem = lookup[itemId]; - if (parentId === null || parentId === undefined || conf.rootParentIds[parentId]) { + var treeItem = lookup[itemId]; + if (parentId === null || + parentId === undefined || + conf.rootParentIds[parentId]) { // is a root item - rootItems.push(TreeItem); + rootItems.push(treeItem); } else { // has a parent @@ -79,7 +85,7 @@ function arrayToTree(items, config) { } } // add the current item to the parent - lookup[parentId][conf.childrenField].push(TreeItem); + lookup[parentId][conf.childrenField].push(treeItem); } } if (orphanIds === null || orphanIds === void 0 ? void 0 : orphanIds.size) { @@ -98,6 +104,6 @@ exports.arrayToTree = arrayToTree; * @param nestedProperty the chained properties to access the nested property. Eg: 'your.nested.property' */ function getNestedProperty(item, nestedProperty) { - return nestedProperty.split('.').reduce(function (o, i) { return o[i]; }, item); + return nestedProperty.split(".").reduce(function (o, i) { return o[i]; }, item); } //# sourceMappingURL=arrayToTree.js.map \ No newline at end of file diff --git a/build/arrayToTree.js.map b/build/arrayToTree.js.map index ed6bd39..63b5a3d 100644 --- a/build/arrayToTree.js.map +++ b/build/arrayToTree.js.map @@ -1 +1 @@ -{"version":3,"file":"arrayToTree.js","sourceRoot":"","sources":["../src/arrayToTree.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAqBA,IAAM,aAAa,GAAW;IAC5B,EAAE,EAAE,IAAI;IACR,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,MAAM;IACjB,aAAa,EAAE,UAAU;IACzB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE;CAC5B,CAAA;AAED;;GAEG;AACH,SAAgB,WAAW,CAAE,KAAa,EAAE,MAA4B;;IAA5B,uBAAA,EAAA,WAA4B;IACtE,IAAM,IAAI,yBAAgB,aAAa,GAAK,MAAM,CAAE,CAAA;IAErD,iCAAiC;IAChC,IAAM,SAAS,GAAe,EAAE,CAAA;IAEjC,yFAAyF;IACxF,IAA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EhD,mEAAmE;gBACnE,IAAI,SAAS,EAAE;oBACb,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;iBACzB;aACF;YAED,qCAAqC;YACrC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACrD;KACF;IAED,IAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,EAAE;QACnB,MAAM,IAAI,KAAK,CACb,0EAA0E;aACxE,MAAI,KAAK,CAAC,IAAI,CACZ,SAAS,CACV,yFAAsF,CAAA;YACvF,wEAAwE,CAC3E,CAAC;KACH;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAjGD,kCAiGC;AAED;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,IAAU,EAAE,cAAsB;IAC3D,OAAO,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,CAAC,CAAC,EAAJ,CAAI,EAAE,IAAI,CAAC,CAAC;AAChE,CAAC"} \ No newline at end of file diff --git a/build/arrayToTree.spec.js b/build/arrayToTree.spec.js index b2a45af..70f1703 100644 --- a/build/arrayToTree.spec.js +++ b/build/arrayToTree.spec.js @@ -2,397 +2,423 @@ Object.defineProperty(exports, "__esModule", { value: true }); var chai_1 = require("chai"); var arrayToTree_1 = require("./arrayToTree"); -describe('arrayToTree', function () { - it('should work with nested objects', function () { +describe("arrayToTree", function () { + it("should work with nested objects", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: null, custom: 'ü' }, + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: null, custom: "ü" }, ])).to.deep.equal([ { - data: { id: '4', parentId: null, custom: 'abc' }, - children: [{ data: { id: '31', parentId: '4', custom: '12' }, children: [] }], + data: { id: "4", parentId: null, custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], }, { - data: { id: '418', parentId: null, custom: 'ü' }, + data: { id: "418", parentId: null, custom: "ü" }, children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, ], }, ]); }); - it('should work with integer keys', function () { + it("should work with integer keys", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: 4, parentId: null, custom: 'abc' }, - { id: 31, parentId: 4, custom: '12' }, - { id: 1941, parentId: 418, custom: 'de' }, - { id: 1, parentId: 418, custom: 'ZZZz' }, - { id: 418, parentId: null, custom: 'ü' }, + { id: 4, parentId: null, custom: "abc" }, + { id: 31, parentId: 4, custom: "12" }, + { id: 1941, parentId: 418, custom: "de" }, + { id: 1, parentId: 418, custom: "ZZZz" }, + { id: 418, parentId: null, custom: "ü" }, ])).to.deep.equal([ { - data: { id: 4, parentId: null, custom: 'abc' }, - children: [{ data: { id: 31, parentId: 4, custom: '12' }, children: [] }], + data: { id: 4, parentId: null, custom: "abc" }, + children: [ + { data: { id: 31, parentId: 4, custom: "12" }, children: [] }, + ], }, { - data: { id: 418, parentId: null, custom: 'ü' }, + data: { id: 418, parentId: null, custom: "ü" }, children: [ - { data: { id: 1941, parentId: 418, custom: 'de' }, children: [] }, - { data: { id: 1, parentId: 418, custom: 'ZZZz' }, children: [] }, + { data: { id: 1941, parentId: 418, custom: "de" }, children: [] }, + { data: { id: 1, parentId: 418, custom: "ZZZz" }, children: [] }, ], }, ]); }); - it('should work with nested objects and custom keys', function () { + it("should work with nested objects and custom keys", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { num: '4', ref: null, custom: 'abc' }, - { num: '31', ref: '4', custom: '12' }, - { num: '1941', ref: '418', custom: 'de' }, - { num: '1', ref: '418', custom: 'ZZZz' }, - { num: '418', ref: null, custom: 'ü' }, - ], { id: 'num', parentId: 'ref', childrenField: 'nodes' })).to.deep.equal([ + { num: "4", ref: null, custom: "abc" }, + { num: "31", ref: "4", custom: "12" }, + { num: "1941", ref: "418", custom: "de" }, + { num: "1", ref: "418", custom: "ZZZz" }, + { num: "418", ref: null, custom: "ü" }, + ], { id: "num", parentId: "ref", childrenField: "nodes" })).to.deep.equal([ { - data: { num: '4', ref: null, custom: 'abc' }, - nodes: [{ data: { num: '31', ref: '4', custom: '12' }, nodes: [] }], + data: { num: "4", ref: null, custom: "abc" }, + nodes: [{ data: { num: "31", ref: "4", custom: "12" }, nodes: [] }], }, { - data: { num: '418', ref: null, custom: 'ü' }, + data: { num: "418", ref: null, custom: "ü" }, nodes: [ - { data: { num: '1941', ref: '418', custom: 'de' }, nodes: [] }, - { data: { num: '1', ref: '418', custom: 'ZZZz' }, nodes: [] }, + { data: { num: "1941", ref: "418", custom: "de" }, nodes: [] }, + { data: { num: "1", ref: "418", custom: "ZZZz" }, nodes: [] }, ], }, ]); }); - it('should ignore objects if parentId does not exist', function () { + it("should ignore objects if parentId does not exist", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: null, custom: 'ü' }, - { id: '1313', parentId: '13', custom: 'Not existing' }, + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: null, custom: "ü" }, + { id: "1313", parentId: "13", custom: "Not existing" }, ])).to.deep.equal([ { - data: { id: '4', parentId: null, custom: 'abc' }, - children: [{ data: { id: '31', parentId: '4', custom: '12' }, children: [] }], + data: { id: "4", parentId: null, custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], }, { - data: { id: '418', parentId: null, custom: 'ü' }, + data: { id: "418", parentId: null, custom: "ü" }, children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, ], }, ]); }); - it('should work with nested objects with dataField set to null', function () { + it("should work with nested objects with dataField set to null", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: null, custom: 'ü' }, + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: null, custom: "ü" }, ], { dataField: null })).to.deep.equal([ { - id: '4', + id: "4", parentId: null, - custom: 'abc', - children: [{ id: '31', parentId: '4', custom: '12', children: [] }], + custom: "abc", + children: [{ id: "31", parentId: "4", custom: "12", children: [] }], }, { - id: '418', + id: "418", parentId: null, - custom: 'ü', + custom: "ü", children: [ - { id: '1941', parentId: '418', custom: 'de', children: [] }, - { id: '1', parentId: '418', custom: 'ZZZz', children: [] }, + { id: "1941", parentId: "418", custom: "de", children: [] }, + { id: "1", parentId: "418", custom: "ZZZz", children: [] }, ], }, ]); }); - it('should work with nested objects and custom keys with dataField set to null', function () { + it("should work with nested objects and custom keys with dataField set to null", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { num: '4', ref: null, custom: 'abc' }, - { num: '31', ref: '4', custom: '12' }, - { num: '1941', ref: '418', custom: 'de' }, - { num: '1', ref: '418', custom: 'ZZZz' }, - { num: '418', ref: null, custom: 'ü' }, - ], { id: 'num', parentId: 'ref', dataField: null })).to.deep.equal([ + { num: "4", ref: null, custom: "abc" }, + { num: "31", ref: "4", custom: "12" }, + { num: "1941", ref: "418", custom: "de" }, + { num: "1", ref: "418", custom: "ZZZz" }, + { num: "418", ref: null, custom: "ü" }, + ], { id: "num", parentId: "ref", dataField: null })).to.deep.equal([ { - num: '4', + num: "4", ref: null, - custom: 'abc', - children: [{ num: '31', ref: '4', custom: '12', children: [] }], + custom: "abc", + children: [{ num: "31", ref: "4", custom: "12", children: [] }], }, { - num: '418', + num: "418", ref: null, - custom: 'ü', + custom: "ü", children: [ - { num: '1941', ref: '418', custom: 'de', children: [] }, - { num: '1', ref: '418', custom: 'ZZZz', children: [] }, + { num: "1941", ref: "418", custom: "de", children: [] }, + { num: "1", ref: "418", custom: "ZZZz", children: [] }, ], }, ]); }); - it('should ignore objects if parentId does not exist with dataField set to null', function () { + it("should ignore objects if parentId does not exist with dataField set to null", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: null, custom: 'ü' }, - { id: '1313', parentId: '13', custom: 'Not existing' }, + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: null, custom: "ü" }, + { id: "1313", parentId: "13", custom: "Not existing" }, ], { dataField: null })).to.deep.equal([ { - id: '4', + id: "4", parentId: null, - custom: 'abc', - children: [{ id: '31', parentId: '4', custom: '12', children: [] }], + custom: "abc", + children: [{ id: "31", parentId: "4", custom: "12", children: [] }], }, { - id: '418', + id: "418", parentId: null, - custom: 'ü', + custom: "ü", children: [ - { id: '1941', parentId: '418', custom: 'de', children: [] }, - { id: '1', parentId: '418', custom: 'ZZZz', children: [] }, + { id: "1941", parentId: "418", custom: "de", children: [] }, + { id: "1", parentId: "418", custom: "ZZZz", children: [] }, ], }, ]); }); - it('should treat objects with missing parentId as root objects', function () { + it("should treat objects with missing parentId as root objects", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '4', custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', custom: 'ü' }, - { id: '1313', parentId: '13', custom: 'Not existing' }, + { id: "4", custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", custom: "ü" }, + { id: "1313", parentId: "13", custom: "Not existing" }, ])).to.deep.equal([ { - data: { id: '4', custom: 'abc' }, - children: [{ data: { id: '31', parentId: '4', custom: '12' }, children: [] }], + data: { id: "4", custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], }, { - data: { id: '418', custom: 'ü' }, + data: { id: "418", custom: "ü" }, children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, ], }, ]); }); - it('should treat objects with empty string as parentId as root objects', function () { + it("should treat objects with empty string as parentId as root objects", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '4', parentId: '', custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: '', custom: 'ü' }, - { id: '1313', parentId: '13', custom: 'Not existing' }, + { id: "4", parentId: "", custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: "", custom: "ü" }, + { id: "1313", parentId: "13", custom: "Not existing" }, ])).to.deep.equal([ { - data: { id: '4', parentId: '', custom: 'abc' }, - children: [{ data: { id: '31', parentId: '4', custom: '12' }, children: [] }], + data: { id: "4", parentId: "", custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], }, { - data: { id: '418', parentId: '', custom: 'ü' }, + data: { id: "418", parentId: "", custom: "ü" }, children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, ], }, ]); }); - it('should treat objects with non-zero length string as parentId as root objects if these parent ids are in rootParentIds', function () { + it("should treat objects with non-zero length string as parentId as root objects if these parent ids are in rootParentIds", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '4', parentId: 'orphan1', custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: 'orphan2', custom: 'ü' }, - { id: '1313', parentId: 'orphan3', custom: 'will be ignored' }, + { id: "4", parentId: "orphan1", custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: "orphan2", custom: "ü" }, + { id: "1313", parentId: "orphan3", custom: "will be ignored" }, ], { - rootParentIds: { '': true, orphan1: true, orphan2: true }, + rootParentIds: { "": true, orphan1: true, orphan2: true }, })).to.deep.equal([ { - data: { id: '4', parentId: 'orphan1', custom: 'abc' }, children: [ - { data: { id: '31', parentId: '4', custom: '12' }, children: [] }, + data: { id: "4", parentId: "orphan1", custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, ], }, { - data: { id: '418', parentId: 'orphan2', custom: 'ü' }, children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, + data: { id: "418", parentId: "orphan2", custom: "ü" }, + children: [ + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, ], }, ]); }); - it('should not throw if orphans exist but throwIfOrphans is false', function () { + it("should not throw if orphans exist but throwIfOrphans is false", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '418', parentId: '6', custom: 'ü' }, + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "418", parentId: "6", custom: "ü" }, ])).to.deep.equal([ { - data: { id: '4', parentId: null, custom: 'abc' }, - children: [{ data: { id: '31', parentId: '4', custom: '12' }, children: [] }], + data: { id: "4", parentId: null, custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], }, ]); }); - it('should throw if orphans exist and throwIfOrphans is true', function () { + it("should throw if orphans exist and throwIfOrphans is true", function () { chai_1.expect(function () { return arrayToTree_1.arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '418', parentId: '6', custom: 'ü' }, - { id: '419', parentId: '418', custom: 'ü' }, - { id: '420', parentId: '7', custom: 'ü' }, + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "418", parentId: "6", custom: "ü" }, + { id: "419", parentId: "418", custom: "ü" }, + { id: "420", parentId: "7", custom: "ü" }, ], { throwIfOrphans: true }); - }).to.throw('The items array contains orphans that point to the following parentIds: [6,7]. ' + - 'These parentIds do not exist in the items array. ' + - 'Hint: prevent orphans to result in an error by passing the following option: { throwIfOrphans: false }'); + }).to.throw("The items array contains orphans that point to the following parentIds: [6,7]. " + + "These parentIds do not exist in the items array. " + + "Hint: prevent orphans to result in an error by passing the following option: { throwIfOrphans: false }"); }); - it('should not throw if no orphans exist and throwIfOrphans is true, but the order is different (see #18)', function () { + it("should not throw if no orphans exist and throwIfOrphans is true, but the order is different (see #18)", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '2', parentId: 'root', foo: 'bar' }, - { id: '1-1', parentId: '1', foo: 'bar' }, - { id: '1', parentId: 'root', foo: 'bar' }, - { id: 'root', parentId: null, bar: 'bar' }, + { id: "2", parentId: "root", foo: "bar" }, + { id: "1-1", parentId: "1", foo: "bar" }, + { id: "1", parentId: "root", foo: "bar" }, + { id: "root", parentId: null, bar: "bar" }, ], { dataField: null, throwIfOrphans: true })).to.deep.equal([ { - id: 'root', + id: "root", parentId: null, - bar: 'bar', + bar: "bar", children: [ - { id: '2', parentId: 'root', foo: 'bar', children: [] }, + { id: "2", parentId: "root", foo: "bar", children: [] }, { - id: '1', - parentId: 'root', - foo: 'bar', - children: [{ id: '1-1', parentId: '1', foo: 'bar', children: [] }], + id: "1", + parentId: "root", + foo: "bar", + children: [{ id: "1-1", parentId: "1", foo: "bar", children: [] }], }, ], }, ]); }); - it('should throw if orphans exist and throwIfOrphans is true and rootParentIds don\'t contain orphan parentId', function () { - chai_1.expect(function () { return arrayToTree_1.arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '418', parentId: '6', custom: 'ü' }, - { id: '419', parentId: '418', custom: 'ü' }, - { id: '420', parentId: '7', custom: 'ü' }, - ], { - rootParentIds: { '': true, '6': true }, - throwIfOrphans: true, - }); }).to.throw('The items array contains orphans that point to the following parentIds: [7]. ' + - 'These parentIds do not exist in the items array. ' + - 'Hint: prevent orphans to result in an error by passing the following option: { throwIfOrphans: false }'); + it("should throw if orphans exist and throwIfOrphans is true and rootParentIds don't contain orphan parentId", function () { + chai_1.expect(function () { + return arrayToTree_1.arrayToTree([ + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "418", parentId: "6", custom: "ü" }, + { id: "419", parentId: "418", custom: "ü" }, + { id: "420", parentId: "7", custom: "ü" }, + ], { + rootParentIds: { "": true, "6": true }, + throwIfOrphans: true, + }); + }).to.throw("The items array contains orphans that point to the following parentIds: [7]. " + + "These parentIds do not exist in the items array. " + + "Hint: prevent orphans to result in an error by passing the following option: { throwIfOrphans: false }"); }); - it('should throw if a node has parentId that both exists in another node and is in rootParentIds', function () { - chai_1.expect(function () { return arrayToTree_1.arrayToTree([ - { id: 'fakeOrphan', parentId: null }, - { id: 'aaa', parentId: 'fakeOrphan' }, - { id: 'bbb', parentId: 'aaa' }, - { id: 'ccc', parentId: 'bbb' }, - ], { - rootParentIds: { '': true, 'fakeOrphan': true }, - throwIfOrphans: true, - }); }).to.throw('The item array contains a node whose parentId both exists in another node and is in `rootParentIds` ' + + it("should throw if a node has parentId that both exists in another node and is in rootParentIds", function () { + chai_1.expect(function () { + return arrayToTree_1.arrayToTree([ + { id: "fakeOrphan", parentId: null }, + { id: "aaa", parentId: "fakeOrphan" }, + { id: "bbb", parentId: "aaa" }, + { id: "ccc", parentId: "bbb" }, + ], { + rootParentIds: { "": true, fakeOrphan: true }, + throwIfOrphans: true, + }); + }).to.throw("The item array contains a node whose parentId both exists in another node and is in `rootParentIds` " + '(`itemId`: "fakeOrphan", `rootParentIds`: "", "fakeOrphan").'); }); - it('should replace default rootParentIds by the provided value', function () { + it("should replace default rootParentIds by the provided value", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '4', parentId: '', custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '418', parentId: '6', custom: 'ü' }, + { id: "4", parentId: "", custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "418", parentId: "6", custom: "ü" }, ], { - rootParentIds: { '6': true }, + rootParentIds: { "6": true }, })).to.deep.equal([ - { data: { id: '418', parentId: '6', custom: 'ü' }, children: [] }, + { data: { id: "418", parentId: "6", custom: "ü" }, children: [] }, ]); }); - it('should work with empty inputs', function () { + it("should work with empty inputs", function () { chai_1.expect(arrayToTree_1.arrayToTree([])).to.deep.equal([]); }); - it('should work with nested objects and nested id and parentId properties', function () { + it("should work with nested objects and nested id and parentId properties", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { nested: { id: '1', parentId: null, custom: '1' } }, - { nested: { id: '1.1', parentId: '1', custom: '1.1' } }, - { nested: { id: '1.1.1', parentId: '1.1', custom: '1.1.1' } }, - { nested: { id: '1.2', parentId: '1', custom: '1.2' } }, - { nested: { id: '2', parentId: null, custom: '2' } }, - ], { id: 'nested.id', parentId: 'nested.parentId' })).to.deep.equal([ + { nested: { id: "1", parentId: null, custom: "1" } }, + { nested: { id: "1.1", parentId: "1", custom: "1.1" } }, + { nested: { id: "1.1.1", parentId: "1.1", custom: "1.1.1" } }, + { nested: { id: "1.2", parentId: "1", custom: "1.2" } }, + { nested: { id: "2", parentId: null, custom: "2" } }, + ], { id: "nested.id", parentId: "nested.parentId" })).to.deep.equal([ { - data: { nested: { id: '1', parentId: null, custom: '1' } }, + data: { nested: { id: "1", parentId: null, custom: "1" } }, children: [ { - data: { nested: { id: '1.1', parentId: '1', custom: '1.1' } }, + data: { nested: { id: "1.1", parentId: "1", custom: "1.1" } }, children: [ { - data: { nested: { id: '1.1.1', parentId: '1.1', custom: '1.1.1' } }, + data: { + nested: { id: "1.1.1", parentId: "1.1", custom: "1.1.1" }, + }, children: [], }, ], }, { - data: { nested: { id: '1.2', parentId: '1', custom: '1.2' } }, + data: { nested: { id: "1.2", parentId: "1", custom: "1.2" } }, children: [], }, ], }, { - data: { nested: { id: '2', parentId: null, custom: '2' } }, + data: { nested: { id: "2", parentId: null, custom: "2" } }, children: [], }, ]); }); - it('should work with nested id property', function () { + it("should work with nested id property", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { one: { id: '1' }, parentId: null, custom: '1' }, - { one: { id: '1.1' }, parentId: '1', custom: '1.1' }, - ], { id: 'one.id', parentId: 'parentId' })).to.deep.equal([{ - data: { one: { id: '1' }, parentId: null, custom: '1' }, + { one: { id: "1" }, parentId: null, custom: "1" }, + { one: { id: "1.1" }, parentId: "1", custom: "1.1" }, + ], { id: "one.id", parentId: "parentId" })).to.deep.equal([ + { + data: { one: { id: "1" }, parentId: null, custom: "1" }, children: [ { - data: { one: { id: '1.1' }, parentId: '1', custom: '1.1' }, + data: { one: { id: "1.1" }, parentId: "1", custom: "1.1" }, children: [], }, ], - }]); + }, + ]); }); - it('should work with nested parentId property', function () { + it("should work with nested parentId property", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { id: '1', two: { parentId: null }, custom: '1' }, - { id: '1.1', two: { parentId: '1' }, custom: '1.1' }, - ], { id: 'id', parentId: 'two.parentId' })).to.deep.equal([{ - data: { id: '1', two: { parentId: null }, custom: '1' }, + { id: "1", two: { parentId: null }, custom: "1" }, + { id: "1.1", two: { parentId: "1" }, custom: "1.1" }, + ], { id: "id", parentId: "two.parentId" })).to.deep.equal([ + { + data: { id: "1", two: { parentId: null }, custom: "1" }, children: [ { - data: { id: '1.1', two: { parentId: '1' }, custom: '1.1' }, + data: { id: "1.1", two: { parentId: "1" }, custom: "1.1" }, children: [], }, ], - }]); + }, + ]); }); - it('should work with nested id and parentId properties', function () { + it("should work with nested id and parentId properties", function () { chai_1.expect(arrayToTree_1.arrayToTree([ - { one: { id: '1' }, two: { parentId: null }, custom: '1' }, - { one: { id: '1.1' }, two: { parentId: '1' }, custom: '1.1' }, - ], { id: 'one.id', parentId: 'two.parentId' })).to.deep.equal([{ - data: { one: { id: '1' }, two: { parentId: null }, custom: '1' }, + { one: { id: "1" }, two: { parentId: null }, custom: "1" }, + { one: { id: "1.1" }, two: { parentId: "1" }, custom: "1.1" }, + ], { id: "one.id", parentId: "two.parentId" })).to.deep.equal([ + { + data: { one: { id: "1" }, two: { parentId: null }, custom: "1" }, children: [ { - data: { one: { id: '1.1' }, two: { parentId: '1' }, custom: '1.1' }, + data: { one: { id: "1.1" }, two: { parentId: "1" }, custom: "1.1" }, children: [], }, ], - }]); + }, + ]); }); }); //# sourceMappingURL=arrayToTree.spec.js.map \ No newline at end of file diff --git a/build/arrayToTree.spec.js.map b/build/arrayToTree.spec.js.map index c34f3e4..0ce8037 100644 --- a/build/arrayToTree.spec.js.map +++ b/build/arrayToTree.spec.js.map @@ -1 +1 @@ -{"version":3,"file":"arrayToTree.spec.js","sourceRoot":"","sources":["../src/arrayToTree.spec.ts"],"names":[],"mappings":";;AAAA,6BAA6B;AAC7B,6CAA2C;AAE3C,QAAQ,CAAC,aAAa,EAAE;IACtB,EAAE,CAAC,iCAAiC,EAAE;QACpC,aAAM,CAAC,yBAAW,CAAC;YACnB,EAAE,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;YAC1C,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;YACzC,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;YAC7C,EAAE,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;YAC5C,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE;SACzC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;YAChB;gBACE,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;gBAChD,QAAQ,EAAE,CAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MA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AE,MAAM,EAAE,GAAG,EAAE;gBAChE,QAAQ,EAAE;oBACR;wBACE,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE;wBACnE,QAAQ,EAAE,EAAE;qBACb;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 3ba10e9..85b5412 100644 --- a/package.json +++ b/package.json @@ -40,17 +40,19 @@ "codecov": "^3.8.1", "mocha": "^8.2.1", "nyc": "^15.1.0", + "prettier": "^2.2.1", "ts-mocha": "^8.0.0", "tslint": "^6.1.3", - "tslint-config-standard": "^9.0.0", + "tslint-config-prettier": "^1.18.0", "typescript": "^4.1.3", "uglify-js": "^3.7.5" }, "scripts": { - "preversion": "yarn && npm run lint && npm run build && npm run test-and-send-cov-to-coveralls", + "preversion": "yarn && npm run format && npm run lint-fix && npm run build && npm run test", "version": "git add .", "postversion": "git push && git push --tags", "build": "rm -rf build && tsc && npm run uglify", + "format": "yarn prettier --write .", "lint": "tslint --project tsconfig.json './src/**/*.ts'", "lint-fix": "tslint --project tsconfig.json './src/**/*.ts' --fix", "test": "ts-mocha src/**/*.spec.ts --timeout 10000", diff --git a/src/arrayToTree.spec.ts b/src/arrayToTree.spec.ts index bd8ab0a..b88aec9 100644 --- a/src/arrayToTree.spec.ts +++ b/src/arrayToTree.spec.ts @@ -1,474 +1,521 @@ -import { expect } from 'chai' -import { arrayToTree } from './arrayToTree' +import { expect } from "chai"; +import { arrayToTree } from "./arrayToTree"; -describe('arrayToTree', () => { - it('should work with nested objects', () => { - expect(arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: null, custom: 'ü' }, - ])).to.deep.equal([ +describe("arrayToTree", () => { + it("should work with nested objects", () => { + expect( + arrayToTree([ + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: null, custom: "ü" }, + ]) + ).to.deep.equal([ { - data: { id: '4', parentId: null, custom: 'abc' }, - children: [ { data: { id: '31', parentId: '4', custom: '12' }, children: [] } ], + data: { id: "4", parentId: null, custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], }, { - data: { id: '418', parentId: null, custom: 'ü' }, + data: { id: "418", parentId: null, custom: "ü" }, children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, ], }, - ]) - }) + ]); + }); - it('should work with integer keys', () => { - expect(arrayToTree([ - { id: 4, parentId: null, custom: 'abc' }, - { id: 31, parentId: 4, custom: '12' }, - { id: 1941, parentId: 418, custom: 'de' }, - { id: 1, parentId: 418, custom: 'ZZZz' }, - { id: 418, parentId: null, custom: 'ü' }, - ])).to.deep.equal([ + it("should work with integer keys", () => { + expect( + arrayToTree([ + { id: 4, parentId: null, custom: "abc" }, + { id: 31, parentId: 4, custom: "12" }, + { id: 1941, parentId: 418, custom: "de" }, + { id: 1, parentId: 418, custom: "ZZZz" }, + { id: 418, parentId: null, custom: "ü" }, + ]) + ).to.deep.equal([ { - data: { id: 4, parentId: null, custom: 'abc' }, - children: [ { data: { id: 31, parentId: 4, custom: '12' }, children: [] } ], + data: { id: 4, parentId: null, custom: "abc" }, + children: [ + { data: { id: 31, parentId: 4, custom: "12" }, children: [] }, + ], }, { - data: { id: 418, parentId: null, custom: 'ü' }, + data: { id: 418, parentId: null, custom: "ü" }, children: [ - { data: { id: 1941, parentId: 418, custom: 'de' }, children: [] }, - { data: { id: 1, parentId: 418, custom: 'ZZZz' }, children: [] }, + { data: { id: 1941, parentId: 418, custom: "de" }, children: [] }, + { data: { id: 1, parentId: 418, custom: "ZZZz" }, children: [] }, ], }, - ]) - }) + ]); + }); - it('should work with nested objects and custom keys', () => { - expect(arrayToTree( - [ - { num: '4', ref: null, custom: 'abc' }, - { num: '31', ref: '4', custom: '12' }, - { num: '1941', ref: '418', custom: 'de' }, - { num: '1', ref: '418', custom: 'ZZZz' }, - { num: '418', ref: null, custom: 'ü' }, - ], - { id: 'num', parentId: 'ref', childrenField: 'nodes' }, - ), - ).to.deep.equal([ - { - data: { num: '4', ref: null, custom: 'abc' }, - nodes: [ { data: { num: '31', ref: '4', custom: '12' }, nodes: [] } ], - }, - { - data: { num: '418', ref: null, custom: 'ü' }, - nodes: [ - { data: { num: '1941', ref: '418', custom: 'de' }, nodes: [] }, - { data: { num: '1', ref: '418', custom: 'ZZZz' }, nodes: [] }, - ], - }, -]) - }) + it("should work with nested objects and custom keys", () => { + expect( + arrayToTree( + [ + { num: "4", ref: null, custom: "abc" }, + { num: "31", ref: "4", custom: "12" }, + { num: "1941", ref: "418", custom: "de" }, + { num: "1", ref: "418", custom: "ZZZz" }, + { num: "418", ref: null, custom: "ü" }, + ], + { id: "num", parentId: "ref", childrenField: "nodes" } + ) + ).to.deep.equal([ + { + data: { num: "4", ref: null, custom: "abc" }, + nodes: [{ data: { num: "31", ref: "4", custom: "12" }, nodes: [] }], + }, + { + data: { num: "418", ref: null, custom: "ü" }, + nodes: [ + { data: { num: "1941", ref: "418", custom: "de" }, nodes: [] }, + { data: { num: "1", ref: "418", custom: "ZZZz" }, nodes: [] }, + ], + }, + ]); + }); - it('should ignore objects if parentId does not exist', () => { - expect(arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: null, custom: 'ü' }, - { id: '1313', parentId: '13', custom: 'Not existing' }, - ])).to.deep.equal([ + it("should ignore objects if parentId does not exist", () => { + expect( + arrayToTree([ + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: null, custom: "ü" }, + { id: "1313", parentId: "13", custom: "Not existing" }, + ]) + ).to.deep.equal([ { - data: { id: '4', parentId: null, custom: 'abc' }, - children: [ { data: { id: '31', parentId: '4', custom: '12' }, children: [] } ], + data: { id: "4", parentId: null, custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], }, { - data: { id: '418', parentId: null, custom: 'ü' }, + data: { id: "418", parentId: null, custom: "ü" }, children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, ], }, - ]) - }) - - it('should work with nested objects with dataField set to null', () => { - expect(arrayToTree( - [ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: null, custom: 'ü' }, - ], - { dataField: null }, - ), - ).to.deep.equal([ - { - id: '4', - parentId: null, - custom: 'abc', - children: [ { id: '31', parentId: '4', custom: '12', children: [] } ], - }, - { - id: '418', - parentId: null, - custom: 'ü', - children: [ - { id: '1941', parentId: '418', custom: 'de', children: [] }, - { id: '1', parentId: '418', custom: 'ZZZz', children: [] }, - ], - }, -]) - }) + ]); + }); - it('should work with nested objects and custom keys with dataField set to null', () => { - expect(arrayToTree( - [ - { num: '4', ref: null, custom: 'abc' }, - { num: '31', ref: '4', custom: '12' }, - { num: '1941', ref: '418', custom: 'de' }, - { num: '1', ref: '418', custom: 'ZZZz' }, - { num: '418', ref: null, custom: 'ü' }, - ], - { id: 'num', parentId: 'ref', dataField: null }, - ), - ).to.deep.equal([ - { - num: '4', - ref: null, - custom: 'abc', - children: [ { num: '31', ref: '4', custom: '12', children: [] } ], - }, - { - num: '418', - ref: null, - custom: 'ü', - children: [ - { num: '1941', ref: '418', custom: 'de', children: [] }, - { num: '1', ref: '418', custom: 'ZZZz', children: [] }, - ], - }, -]) - }) + it("should work with nested objects with dataField set to null", () => { + expect( + arrayToTree( + [ + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: null, custom: "ü" }, + ], + { dataField: null } + ) + ).to.deep.equal([ + { + id: "4", + parentId: null, + custom: "abc", + children: [{ id: "31", parentId: "4", custom: "12", children: [] }], + }, + { + id: "418", + parentId: null, + custom: "ü", + children: [ + { id: "1941", parentId: "418", custom: "de", children: [] }, + { id: "1", parentId: "418", custom: "ZZZz", children: [] }, + ], + }, + ]); + }); - it('should ignore objects if parentId does not exist with dataField set to null', () => { - expect(arrayToTree( - [ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: null, custom: 'ü' }, - { id: '1313', parentId: '13', custom: 'Not existing' }, - ], - { dataField: null }, - ), - ).to.deep.equal([ - { - id: '4', - parentId: null, - custom: 'abc', - children: [ { id: '31', parentId: '4', custom: '12', children: [] } ], - }, - { - id: '418', - parentId: null, - custom: 'ü', - children: [ - { id: '1941', parentId: '418', custom: 'de', children: [] }, - { id: '1', parentId: '418', custom: 'ZZZz', children: [] }, - ], - }, -]) - }) + it("should work with nested objects and custom keys with dataField set to null", () => { + expect( + arrayToTree( + [ + { num: "4", ref: null, custom: "abc" }, + { num: "31", ref: "4", custom: "12" }, + { num: "1941", ref: "418", custom: "de" }, + { num: "1", ref: "418", custom: "ZZZz" }, + { num: "418", ref: null, custom: "ü" }, + ], + { id: "num", parentId: "ref", dataField: null } + ) + ).to.deep.equal([ + { + num: "4", + ref: null, + custom: "abc", + children: [{ num: "31", ref: "4", custom: "12", children: [] }], + }, + { + num: "418", + ref: null, + custom: "ü", + children: [ + { num: "1941", ref: "418", custom: "de", children: [] }, + { num: "1", ref: "418", custom: "ZZZz", children: [] }, + ], + }, + ]); + }); - it('should treat objects with missing parentId as root objects', () => { - expect(arrayToTree([ - { id: '4', custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', custom: 'ü' }, - { id: '1313', parentId: '13', custom: 'Not existing' }, - ])).to.deep.equal([ + it("should ignore objects if parentId does not exist with dataField set to null", () => { + expect( + arrayToTree( + [ + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: null, custom: "ü" }, + { id: "1313", parentId: "13", custom: "Not existing" }, + ], + { dataField: null } + ) + ).to.deep.equal([ { - data: { id: '4', custom: 'abc' }, - children: [ { data: { id: '31', parentId: '4', custom: '12' }, children: [] } ], + id: "4", + parentId: null, + custom: "abc", + children: [{ id: "31", parentId: "4", custom: "12", children: [] }], }, { - data: { id: '418', custom: 'ü' }, + id: "418", + parentId: null, + custom: "ü", children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, + { id: "1941", parentId: "418", custom: "de", children: [] }, + { id: "1", parentId: "418", custom: "ZZZz", children: [] }, ], }, - ]) - }) + ]); + }); - it('should treat objects with empty string as parentId as root objects', () => { - expect(arrayToTree([ - { id: '4', parentId: '', custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: '', custom: 'ü' }, - { id: '1313', parentId: '13', custom: 'Not existing' }, - ])).to.deep.equal([ + it("should treat objects with missing parentId as root objects", () => { + expect( + arrayToTree([ + { id: "4", custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", custom: "ü" }, + { id: "1313", parentId: "13", custom: "Not existing" }, + ]) + ).to.deep.equal([ { - data: { id: '4', parentId: '', custom: 'abc' }, - children: [ { data: { id: '31', parentId: '4', custom: '12' }, children: [] } ], + data: { id: "4", custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], }, { - data: { id: '418', parentId: '', custom: 'ü' }, + data: { id: "418", custom: "ü" }, children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, ], }, - ]) - }) + ]); + }); - it('should treat objects with non-zero length string as parentId as root objects if these parent ids are in rootParentIds', () => { - expect(arrayToTree( - [ - { id: '4', parentId: 'orphan1', custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '1941', parentId: '418', custom: 'de' }, - { id: '1', parentId: '418', custom: 'ZZZz' }, - { id: '418', parentId: 'orphan2', custom: 'ü' }, - { id: '1313', parentId: 'orphan3', custom: 'will be ignored' }, - ], + it("should treat objects with empty string as parentId as root objects", () => { + expect( + arrayToTree([ + { id: "4", parentId: "", custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: "", custom: "ü" }, + { id: "1313", parentId: "13", custom: "Not existing" }, + ]) + ).to.deep.equal([ { - rootParentIds: { '': true, orphan1: true, orphan2: true }, + data: { id: "4", parentId: "", custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], }, - )).to.deep.equal([ { - data: { id: '4', parentId: 'orphan1', custom: 'abc' }, children: [ - { data: { id: '31', parentId: '4', custom: '12' }, children: [] }, + data: { id: "418", parentId: "", custom: "ü" }, + children: [ + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, + ], + }, + ]); + }); + + it("should treat objects with non-zero length string as parentId as root objects if these parent ids are in rootParentIds", () => { + expect( + arrayToTree( + [ + { id: "4", parentId: "orphan1", custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "1941", parentId: "418", custom: "de" }, + { id: "1", parentId: "418", custom: "ZZZz" }, + { id: "418", parentId: "orphan2", custom: "ü" }, + { id: "1313", parentId: "orphan3", custom: "will be ignored" }, + ], + { + rootParentIds: { "": true, orphan1: true, orphan2: true }, + } + ) + ).to.deep.equal([ + { + data: { id: "4", parentId: "orphan1", custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, ], }, { - data: { id: '418', parentId: 'orphan2', custom: 'ü' }, children: [ - { data: { id: '1941', parentId: '418', custom: 'de' }, children: [] }, - { data: { id: '1', parentId: '418', custom: 'ZZZz' }, children: [] }, + data: { id: "418", parentId: "orphan2", custom: "ü" }, + children: [ + { data: { id: "1941", parentId: "418", custom: "de" }, children: [] }, + { data: { id: "1", parentId: "418", custom: "ZZZz" }, children: [] }, ], }, - ]) - }) + ]); + }); - it('should not throw if orphans exist but throwIfOrphans is false', () => { - expect(arrayToTree([ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '418', parentId: '6', custom: 'ü' }, - ])).to.deep.equal([ + it("should not throw if orphans exist but throwIfOrphans is false", () => { + expect( + arrayToTree([ + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "418", parentId: "6", custom: "ü" }, + ]) + ).to.deep.equal([ { - data: { id: '4', parentId: null, custom: 'abc' }, - children: [ { data: { id: '31', parentId: '4', custom: '12' }, children: [] } ], + data: { id: "4", parentId: null, custom: "abc" }, + children: [ + { data: { id: "31", parentId: "4", custom: "12" }, children: [] }, + ], }, - ]) - }) + ]); + }); - it('should throw if orphans exist and throwIfOrphans is true', () => { + it("should throw if orphans exist and throwIfOrphans is true", () => { expect(() => - arrayToTree( - [ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '418', parentId: '6', custom: 'ü' }, - { id: '419', parentId: '418', custom: 'ü' }, - { id: '420', parentId: '7', custom: 'ü' }, - ], - { throwIfOrphans: true }, - ), - ).to.throw( - 'The items array contains orphans that point to the following parentIds: [6,7]. ' + - 'These parentIds do not exist in the items array. ' + - 'Hint: prevent orphans to result in an error by passing the following option: { throwIfOrphans: false }', - ) - }) + arrayToTree( + [ + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "418", parentId: "6", custom: "ü" }, + { id: "419", parentId: "418", custom: "ü" }, + { id: "420", parentId: "7", custom: "ü" }, + ], + { throwIfOrphans: true } + ) + ).to.throw( + "The items array contains orphans that point to the following parentIds: [6,7]. " + + "These parentIds do not exist in the items array. " + + "Hint: prevent orphans to result in an error by passing the following option: { throwIfOrphans: false }" + ); + }); - it('should not throw if no orphans exist and throwIfOrphans is true, but the order is different (see #18)', () => { - expect(arrayToTree( - [ - { id: '2', parentId: 'root', foo: 'bar' }, - { id: '1-1', parentId: '1', foo: 'bar' }, - { id: '1', parentId: 'root', foo: 'bar' }, - { id: 'root', parentId: null, bar: 'bar' }, - ], - { dataField: null, throwIfOrphans: true }, - ), - ).to.deep.equal([ - { - id: 'root', - parentId: null, - bar: 'bar', - children: [ - { id: '2', parentId: 'root', foo: 'bar', children: [] }, + it("should not throw if no orphans exist and throwIfOrphans is true, but the order is different (see #18)", () => { + expect( + arrayToTree( + [ + { id: "2", parentId: "root", foo: "bar" }, + { id: "1-1", parentId: "1", foo: "bar" }, + { id: "1", parentId: "root", foo: "bar" }, + { id: "root", parentId: null, bar: "bar" }, + ], + { dataField: null, throwIfOrphans: true } + ) + ).to.deep.equal([ { - id: '1', - parentId: 'root', - foo: 'bar', - children: [ { id: '1-1', parentId: '1', foo: 'bar', children: [] } ], + id: "root", + parentId: null, + bar: "bar", + children: [ + { id: "2", parentId: "root", foo: "bar", children: [] }, + { + id: "1", + parentId: "root", + foo: "bar", + children: [{ id: "1-1", parentId: "1", foo: "bar", children: [] }], + }, + ], }, - ], - }, -]) - }) + ]); + }); - it('should throw if orphans exist and throwIfOrphans is true and rootParentIds don\'t contain orphan parentId', () => { - expect( - () => arrayToTree( + it("should throw if orphans exist and throwIfOrphans is true and rootParentIds don't contain orphan parentId", () => { + expect(() => + arrayToTree( [ - { id: '4', parentId: null, custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '418', parentId: '6', custom: 'ü' }, - { id: '419', parentId: '418', custom: 'ü' }, - { id: '420', parentId: '7', custom: 'ü' }, + { id: "4", parentId: null, custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "418", parentId: "6", custom: "ü" }, + { id: "419", parentId: "418", custom: "ü" }, + { id: "420", parentId: "7", custom: "ü" }, ], { - rootParentIds: { '': true, '6': true }, + rootParentIds: { "": true, "6": true }, throwIfOrphans: true, - }, - ), + } + ) ).to.throw( - 'The items array contains orphans that point to the following parentIds: [7]. ' + - 'These parentIds do not exist in the items array. ' + - 'Hint: prevent orphans to result in an error by passing the following option: { throwIfOrphans: false }', - ) - }) + "The items array contains orphans that point to the following parentIds: [7]. " + + "These parentIds do not exist in the items array. " + + "Hint: prevent orphans to result in an error by passing the following option: { throwIfOrphans: false }" + ); + }); - it('should throw if a node has parentId that both exists in another node and is in rootParentIds', () => { - expect( - () => arrayToTree( + it("should throw if a node has parentId that both exists in another node and is in rootParentIds", () => { + expect(() => + arrayToTree( [ - { id: 'fakeOrphan', parentId: null }, - { id: 'aaa', parentId: 'fakeOrphan' }, - { id: 'bbb', parentId: 'aaa' }, - { id: 'ccc', parentId: 'bbb' }, + { id: "fakeOrphan", parentId: null }, + { id: "aaa", parentId: "fakeOrphan" }, + { id: "bbb", parentId: "aaa" }, + { id: "ccc", parentId: "bbb" }, ], { - rootParentIds: { '': true, 'fakeOrphan': true }, + rootParentIds: { "": true, fakeOrphan: true }, throwIfOrphans: true, - }, - ), + } + ) ).to.throw( - 'The item array contains a node whose parentId both exists in another node and is in `rootParentIds` ' + - '(`itemId`: "fakeOrphan", `rootParentIds`: "", "fakeOrphan").', - ) - }) + "The item array contains a node whose parentId both exists in another node and is in `rootParentIds` " + + '(`itemId`: "fakeOrphan", `rootParentIds`: "", "fakeOrphan").' + ); + }); - it('should replace default rootParentIds by the provided value', () => { + it("should replace default rootParentIds by the provided value", () => { expect( - arrayToTree([ - { id: '4', parentId: '', custom: 'abc' }, - { id: '31', parentId: '4', custom: '12' }, - { id: '418', parentId: '6', custom: 'ü' }, - ], { - rootParentIds: { '6': true }, - }, - )).to.deep.equal([ - { data: { id: '418', parentId: '6', custom: 'ü' }, children: [] }, - ]) - }) + arrayToTree( + [ + { id: "4", parentId: "", custom: "abc" }, + { id: "31", parentId: "4", custom: "12" }, + { id: "418", parentId: "6", custom: "ü" }, + ], + { + rootParentIds: { "6": true }, + } + ) + ).to.deep.equal([ + { data: { id: "418", parentId: "6", custom: "ü" }, children: [] }, + ]); + }); - it('should work with empty inputs', () => { - expect(arrayToTree([])).to.deep.equal([]) - }) + it("should work with empty inputs", () => { + expect(arrayToTree([])).to.deep.equal([]); + }); - it('should work with nested objects and nested id and parentId properties', () => { - expect(arrayToTree( - [ - { nested: { id: '1', parentId: null, custom: '1' } }, - { nested: { id: '1.1', parentId: '1', custom: '1.1' } }, - { nested: { id: '1.1.1', parentId: '1.1', custom: '1.1.1' } }, - { nested: { id: '1.2', parentId: '1', custom: '1.2' } }, - { nested: { id: '2', parentId: null, custom: '2' } }, - ], - { id: 'nested.id', parentId: 'nested.parentId' }, - ), - ).to.deep.equal([ - { - data: { nested: { id: '1', parentId: null, custom: '1' } }, - children: [ + it("should work with nested objects and nested id and parentId properties", () => { + expect( + arrayToTree( + [ + { nested: { id: "1", parentId: null, custom: "1" } }, + { nested: { id: "1.1", parentId: "1", custom: "1.1" } }, + { nested: { id: "1.1.1", parentId: "1.1", custom: "1.1.1" } }, + { nested: { id: "1.2", parentId: "1", custom: "1.2" } }, + { nested: { id: "2", parentId: null, custom: "2" } }, + ], + { id: "nested.id", parentId: "nested.parentId" } + ) + ).to.deep.equal([ { - data: { nested: { id: '1.1', parentId: '1', custom: '1.1' } }, + data: { nested: { id: "1", parentId: null, custom: "1" } }, children: [ { - data: { nested: { id: '1.1.1', parentId: '1.1', custom: '1.1.1' } }, + data: { nested: { id: "1.1", parentId: "1", custom: "1.1" } }, + children: [ + { + data: { + nested: { id: "1.1.1", parentId: "1.1", custom: "1.1.1" }, + }, + children: [], + }, + ], + }, + { + data: { nested: { id: "1.2", parentId: "1", custom: "1.2" } }, children: [], }, ], }, { - data: { nested: { id: '1.2', parentId: '1', custom: '1.2' } }, + data: { nested: { id: "2", parentId: null, custom: "2" } }, children: [], }, - ], - }, - { - data: { nested: { id: '2', parentId: null, custom: '2' } }, - children: [], - }, -]) - - }) - it('should work with nested id property', () => { - expect(arrayToTree( - [ - { one: { id: '1' }, parentId: null, custom: '1' }, - { one: { id: '1.1' }, parentId: '1', custom: '1.1' }, - ], - { id: 'one.id', parentId: 'parentId' }, - ), - ).to.deep.equal([{ - data: { one: { id: '1' }, parentId: null, custom: '1' }, - children: [ - { - data: { one: { id: '1.1' }, parentId: '1', custom: '1.1' }, - children: [], - }, - ], -}]) - }) - it('should work with nested parentId property', () => { - expect(arrayToTree( - [ - { id: '1', two: { parentId: null }, custom: '1' }, - { id: '1.1', two: { parentId: '1' }, custom: '1.1' }, - ], - { id: 'id', parentId: 'two.parentId' }, - ), - ).to.deep.equal([{ - data: { id: '1', two: { parentId: null }, custom: '1' }, - children: [ - { - data: { id: '1.1', two: { parentId: '1' }, custom: '1.1' }, - children: [], - }, - ], -}]) - }) - it('should work with nested id and parentId properties', () => { - expect(arrayToTree( - [ - { one: { id: '1' }, two: { parentId: null }, custom: '1' }, - { one: { id: '1.1' }, two: { parentId: '1' }, custom: '1.1' }, - ], - { id: 'one.id', parentId: 'two.parentId' }, - ), - ).to.deep.equal([{ - data: { one: { id: '1' }, two: { parentId: null }, custom: '1' }, - children: [ - { - data: { one: { id: '1.1' }, two: { parentId: '1' }, custom: '1.1' }, - children: [], - }, - ], -}]) - }) -}) + ]); + }); + it("should work with nested id property", () => { + expect( + arrayToTree( + [ + { one: { id: "1" }, parentId: null, custom: "1" }, + { one: { id: "1.1" }, parentId: "1", custom: "1.1" }, + ], + { id: "one.id", parentId: "parentId" } + ) + ).to.deep.equal([ + { + data: { one: { id: "1" }, parentId: null, custom: "1" }, + children: [ + { + data: { one: { id: "1.1" }, parentId: "1", custom: "1.1" }, + children: [], + }, + ], + }, + ]); + }); + it("should work with nested parentId property", () => { + expect( + arrayToTree( + [ + { id: "1", two: { parentId: null }, custom: "1" }, + { id: "1.1", two: { parentId: "1" }, custom: "1.1" }, + ], + { id: "id", parentId: "two.parentId" } + ) + ).to.deep.equal([ + { + data: { id: "1", two: { parentId: null }, custom: "1" }, + children: [ + { + data: { id: "1.1", two: { parentId: "1" }, custom: "1.1" }, + children: [], + }, + ], + }, + ]); + }); + it("should work with nested id and parentId properties", () => { + expect( + arrayToTree( + [ + { one: { id: "1" }, two: { parentId: null }, custom: "1" }, + { one: { id: "1.1" }, two: { parentId: "1" }, custom: "1.1" }, + ], + { id: "one.id", parentId: "two.parentId" } + ) + ).to.deep.equal([ + { + data: { one: { id: "1" }, two: { parentId: null }, custom: "1" }, + children: [ + { + data: { one: { id: "1.1" }, two: { parentId: "1" }, custom: "1.1" }, + children: [], + }, + ], + }, + ]); + }); +}); diff --git a/src/arrayToTree.ts b/src/arrayToTree.ts index 69db27c..e0d9559 100644 --- a/src/arrayToTree.ts +++ b/src/arrayToTree.ts @@ -1,116 +1,133 @@ export interface Item { - id?: string | number - parentId?: string | number | null - [key: string]: any + id?: string | number; + parentId?: string | number | null; + [key: string]: any; } export interface TreeItem { - id?: string | number - parentId?: string | number | null - [key: string]: Item | TreeItem[] | any + id?: string | number; + parentId?: string | number | null; + [key: string]: Item | TreeItem[] | any; } export interface Config { - id: string, - parentId: string, - dataField: string | null, - childrenField: string, - throwIfOrphans: boolean, - rootParentIds: { [rootParentId: string]: true }, // use an object here for fast lookups + id: string; + parentId: string; + dataField: string | null; + childrenField: string; + throwIfOrphans: boolean; + rootParentIds: { [rootParentId: string]: true }; // use an object here for fast lookups } const defaultConfig: Config = { - id: 'id', - parentId: 'parentId', - dataField: 'data', - childrenField: 'children', + id: "id", + parentId: "parentId", + dataField: "data", + childrenField: "children", throwIfOrphans: false, - rootParentIds: { '': true }, -} + rootParentIds: { "": true }, +}; /** * Unflattens an array to a tree with runtime O(n) */ -export function arrayToTree (items: Item[], config: Partial = {}): TreeItem[] { - const conf: Config = { ...defaultConfig, ...config } - - // the resulting unflattened tree - const rootItems: TreeItem[] = [] - - // stores all already processed items with their ids as key so we can easily look them up - const lookup: { [id: string]: TreeItem } = {} - - // stores all item ids that have not been added to the resulting unflattened tree yet - // this is an opt-in property, since it has a slight runtime overhead - const orphanIds: null | Set = config.throwIfOrphans ? new Set() : null - - // idea of this loop: - // whenever an item has a parent, but the parent is not yet in the lookup object, we store a preliminary parent - // in the lookup object and fill it with the data of the parent later - // if an item has no parentId, add it as a root element to rootItems +export function arrayToTree( + items: Item[], + config: Partial = {} +): TreeItem[] { + const conf: Config = { ...defaultConfig, ...config }; + + // the resulting unflattened tree + const rootItems: TreeItem[] = []; + + // stores all already processed items with their ids as key so we can easily look them up + const lookup: { [id: string]: TreeItem } = {}; + + // stores all item ids that have not been added to the resulting unflattened tree yet + // this is an opt-in property, since it has a slight runtime overhead + const orphanIds: null | Set = config.throwIfOrphans + ? new Set() + : null; + + // idea of this loop: + // whenever an item has a parent, but the parent is not yet in the lookup object, we store a preliminary parent + // in the lookup object and fill it with the data of the parent later + // if an item has no parentId, add it as a root element to rootItems for (const item of items) { - const itemId = getNestedProperty(item, conf.id) - const parentId = getNestedProperty(item, conf.parentId) + const itemId = getNestedProperty(item, conf.id); + const parentId = getNestedProperty(item, conf.parentId); if (conf.rootParentIds[itemId]) { - throw new Error(`The item array contains a node whose parentId both exists in another node and is in ` + - `\`rootParentIds\` (\`itemId\`: "${itemId}", \`rootParentIds\`: ${ - Object.keys(conf.rootParentIds).map(r => `"${r}"`).join(', ')}).`) + throw new Error( + `The item array contains a node whose parentId both exists in another node and is in ` + + `\`rootParentIds\` (\`itemId\`: "${itemId}", \`rootParentIds\`: ${Object.keys( + conf.rootParentIds + ) + .map((r) => `"${r}"`) + .join(", ")}).` + ); } // look whether item already exists in the lookup table if (!Object.prototype.hasOwnProperty.call(lookup, itemId)) { - // item is not yet there, so add a preliminary item (its data will be added later) - lookup[itemId] = { [conf.childrenField]: [] } + // item is not yet there, so add a preliminary item (its data will be added later) + lookup[itemId] = { [conf.childrenField]: [] }; } - // if we track orphans, delete this item from the orphan set if it is in it + // if we track orphans, delete this item from the orphan set if it is in it if (orphanIds) { - orphanIds.delete(itemId) + orphanIds.delete(itemId); } - // add the current item's data to the item in the lookup table + // add the current item's data to the item in the lookup table if (conf.dataField) { - lookup[itemId][conf.dataField] = item + lookup[itemId][conf.dataField] = item; } else { - lookup[itemId] = { ...item, [conf.childrenField]: lookup[itemId][conf.childrenField] } + lookup[itemId] = { + ...item, + [conf.childrenField]: lookup[itemId][conf.childrenField], + }; } - const TreeItem = lookup[itemId] + const treeItem = lookup[itemId]; - if (parentId === null || parentId === undefined || conf.rootParentIds[parentId]) { + if ( + parentId === null || + parentId === undefined || + conf.rootParentIds[parentId] + ) { // is a root item - rootItems.push(TreeItem) + rootItems.push(treeItem); } else { - // has a parent + // has a parent - // look whether the parent already exists in the lookup table + // look whether the parent already exists in the lookup table if (!Object.prototype.hasOwnProperty.call(lookup, parentId)) { - // parent is not yet there, so add a preliminary parent (its data will be added later) - lookup[parentId] = { [conf.childrenField]: [] } + // parent is not yet there, so add a preliminary parent (its data will be added later) + lookup[parentId] = { [conf.childrenField]: [] }; - // if we track orphans, add the generated parent to the orphan list + // if we track orphans, add the generated parent to the orphan list if (orphanIds) { - orphanIds.add(parentId) + orphanIds.add(parentId); } } - // add the current item to the parent - lookup[parentId][conf.childrenField].push(TreeItem) + // add the current item to the parent + lookup[parentId][conf.childrenField].push(treeItem); } } if (orphanIds?.size) { throw new Error( - `The items array contains orphans that point to the following parentIds: ` + - `[${Array.from( - orphanIds, - )}]. These parentIds do not exist in the items array. Hint: prevent orphans to result ` + - `in an error by passing the following option: { throwIfOrphans: false }`, - ) + `The items array contains orphans that point to the following parentIds: ` + + `[${Array.from( + orphanIds + )}]. These parentIds do not exist in the items array. Hint: prevent orphans to result ` + + `in an error by passing the following option: { throwIfOrphans: false }` + ); } - return rootItems + return rootItems; } /** @@ -120,6 +137,6 @@ export function arrayToTree (items: Item[], config: Partial = {}): TreeI * @param item * @param nestedProperty the chained properties to access the nested property. Eg: 'your.nested.property' */ -function getNestedProperty (item: Item, nestedProperty: string) { - return nestedProperty.split('.').reduce((o, i) => o[i], item) +function getNestedProperty(item: Item, nestedProperty: string) { + return nestedProperty.split(".").reduce((o, i) => o[i], item); } diff --git a/tsconfig.json b/tsconfig.json index 3155af5..d576017 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,8 +10,5 @@ "strictNullChecks": true, "lib": ["ES6"] }, - "exclude": [ - "node_modules", - "typings" - ] -} \ No newline at end of file + "exclude": ["node_modules", "typings"] +} diff --git a/tslint.json b/tslint.json index 47f7b2e..7a03cfd 100644 --- a/tslint.json +++ b/tslint.json @@ -1,6 +1,6 @@ { - "extends": "tslint-config-standard", + "extends": ["tslint:latest", "tslint-config-prettier"], "rules": { - "trailing-comma": [true, {"multiline": "always", "singleline": "never"}] + "no-implicit-dependencies": [true, "dev"] } } diff --git a/yarn.lock b/yarn.lock index 451f053..7a8b890 100644 --- a/yarn.lock +++ b/yarn.lock @@ -559,14 +559,6 @@ diff@^3.1.0: resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA== -doctrine@0.7.2: - version "0.7.2" - resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-0.7.2.tgz#7cb860359ba3be90e040b26b729ce4bfa654c523" - integrity sha1-fLhgNZujvpDgQLJrcpzkv6ZUxSM= - dependencies: - esutils "^1.1.6" - isarray "0.0.1" - emoji-regex@^7.0.1: version "7.0.3" resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156" @@ -597,11 +589,6 @@ esprima@^4.0.0: resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== -esutils@^1.1.6: - version "1.1.6" - resolved "https://registry.yarnpkg.com/esutils/-/esutils-1.1.6.tgz#c01ccaa9ae4b897c6d0c3e210ae52f3c7a844375" - integrity sha1-wBzKqa5LiXxtDD4hCuUvPHqEQ3U= - fill-range@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40" @@ -871,11 +858,6 @@ is-windows@^1.0.2: resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== -isarray@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" - integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= - isexe@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" @@ -1249,6 +1231,11 @@ pkg-dir@^4.1.0: dependencies: find-up "^4.0.0" +prettier@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5" + integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q== + process-on-spawn@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/process-on-spawn/-/process-on-spawn-1.0.0.tgz#95b05a23073d30a17acfdc92a440efd2baefdc93" @@ -1544,31 +1531,15 @@ tsconfig-paths@^3.5.0: minimist "^1.2.0" strip-bom "^3.0.0" -tslib@1.9.0: - version "1.9.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8" - integrity sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ== - tslib@^1.13.0, tslib@^1.8.1: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslint-config-standard@^9.0.0: - version "9.0.0" - resolved "https://registry.yarnpkg.com/tslint-config-standard/-/tslint-config-standard-9.0.0.tgz#349a94819d93d5f8d803e3c71cb58ef38eff88e0" - integrity sha512-CAw9J743RnPMemQV/XQ4YyNreC+A1NItACfkm+cBedrOkz6CQfwlnbKn8anUXBfoa4Zo4tjAhblRbsMNcSLfSw== - dependencies: - tslint-eslint-rules "^5.3.1" - -tslint-eslint-rules@^5.3.1: - version "5.4.0" - resolved "https://registry.yarnpkg.com/tslint-eslint-rules/-/tslint-eslint-rules-5.4.0.tgz#e488cc9181bf193fe5cd7bfca213a7695f1737b5" - integrity sha512-WlSXE+J2vY/VPgIcqQuijMQiel+UtmXS+4nvK4ZzlDiqBfXse8FAvkNnTcYhnQyOTW5KFM+uRRGXxYhFpuBc6w== - dependencies: - doctrine "0.7.2" - tslib "1.9.0" - tsutils "^3.0.0" +tslint-config-prettier@^1.18.0: + version "1.18.0" + resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.18.0.tgz#75f140bde947d35d8f0d238e0ebf809d64592c37" + integrity sha512-xPw9PgNPLG3iKRxmK7DWr+Ea/SzrvfHtjFt5LBl61gk2UBG/DB9kCXRjv+xyIU1rUtnayLeMUVJBcMX8Z17nDg== tslint@^6.1.3: version "6.1.3" @@ -1596,13 +1567,6 @@ tsutils@^2.29.0: dependencies: tslib "^1.8.1" -tsutils@^3.0.0: - version "3.20.0" - resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.20.0.tgz#ea03ea45462e146b53d70ce0893de453ff24f698" - integrity sha512-RYbuQuvkhuqVeXweWT3tJLKOEJ/UUw9GjNEZGWdrLLlM+611o1gwLHBpxoFJKKl25fLprp2eVthtKs5JOrNeXg== - dependencies: - tslib "^1.8.1" - type-detect@^4.0.0, type-detect@^4.0.5: version "4.0.8" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"