diff --git a/build/arrayToTree.js b/build/arrayToTree.js index a311ae4..829c9a8 100644 --- a/build/arrayToTree.js +++ b/build/arrayToTree.js @@ -51,9 +51,9 @@ function arrayToTree(items, config) { : 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`: \"".concat(itemId, "\", `rootParentIds`: ").concat(Object.keys(conf.rootParentIds) + .map(function (r) { return "\"".concat(r, "\""); }) + .join(", "), ").")); } // look whether item already exists in the lookup table if (!Object.prototype.hasOwnProperty.call(lookup, itemId)) { @@ -95,7 +95,7 @@ function arrayToTree(items, config) { } if (orphanIds === null || orphanIds === void 0 ? void 0 : 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 ") + + "[".concat(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; @@ -109,6 +109,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 && 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 52a92ea..22d002c 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":";;;;;;;;;;;;;;AAkBA,IAAM,aAAa,GAAW;IAC5B,EAAE,EAAE,IAAI;IACR,QAAQ,EA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,SAAS,iBAAiB,CAAC,IAAU,EAAE,cAAsB;IAC3D,OAAO,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAT,CAAS,EAAE,IAAI,CAAC,CAAC;AACrE,CAAC"} \ No newline at end of file diff --git a/build/arrayToTree.min.js b/build/arrayToTree.min.js index 5a71877..baff331 100644 --- a/build/arrayToTree.min.js +++ b/build/arrayToTree.min.js @@ -1 +1 @@ -"use strict";var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var r,t=1,n=arguments.length;t