Skip to content

Commit 864224e

Browse files
committed
Add rootParentIds option to fit the case when all items contain a valid parentId string
1 parent f8773dc commit 864224e

File tree

10 files changed

+101
-6
lines changed

10 files changed

+101
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ You can provide a second argument to arrayToTree with configuration options. Rig
6464
- `childrenField`: key which will contain all child nodes of the parent node. Default: `"children"`
6565
- `dataField`: key which will contain all properties/data of the original items. Set to null if you don't want a container. Default: `"data"`
6666
- `throwIfOrphans`: option to throw an error if the array of items contains one or more items that have no parents in the array. This option has a small runtime penalty, so it's disabled by default. When enabled, the function will throw an error containing the parentIds that were not found in the items array. When disabled, the function will just ignore orphans and not add them to the tree. Default: `false`
67+
- `rootParentIds`: key array used to specify an item whose parent id is an orphan, but you don't want it and it's sub items to be ignored. It's useful when your tree is a subset of full tree, which means there is no item whose parent id is one of `undefined` / `null` / `''`. The array you pass in will be merged with the default value. See[#23](https://github.com/philipstanislaus/performant-array-to-tree/issues/23). Default: `[null, undefined, '']`
6768

6869
Example:
6970

build/arrayToTree.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface Config {
1414
dataField: string | null;
1515
childrenField: string;
1616
throwIfOrphans: boolean;
17+
rootParentIds: (string | undefined | null)[];
1718
}
1819
/**
1920
* Unflattens an array to a tree with runtime O(n)

build/arrayToTree.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/arrayToTree.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/arrayToTree.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/arrayToTree.spec.js

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)