fast-tree-builder 2.0.0-beta.5 → 2.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,14 +71,20 @@ Builds a tree structure from an iterable list of items.
|
|
|
71
71
|
- `parentKey`: Key where the node's parent reference is stored in the output node. Set to `false` to omit parent links. Defaults to `'parent'`.
|
|
72
72
|
- `childrenKey`: Key where the node's children are stored in the output node. Defaults to `'children'`.
|
|
73
73
|
- `depthKey`: Key where the node's depth (with root = 0) is stored in the output node. Set to `false` to omit depth values. Setting this enables validateTree implicitly, as depth calculation requires full tree validation. Defaults to `false`.
|
|
74
|
-
- `validateReferences`: When `true`, verifies all `parentId` or `childIds` resolve to real items. Errors are thrown on invalid references. Defaults to `false`.
|
|
74
|
+
- `validateReferences`: When `true`, verifies all `parentId` or `childIds` resolve to real items. Only `null` and `undefined` are acceptable parent ids for root nodes when enabled. Errors are thrown on invalid references. Defaults to `false`.
|
|
75
75
|
- `validateTree`: When `true`, verifies that the final structure is a valid tree (no cycles or nodes reachable via multiple paths). Errors are thrown if the check fails. Defaults to `false`.
|
|
76
76
|
|
|
77
|
-
> **Accessors vs. Output Keys**
|
|
77
|
+
> **Input Accessors vs. Output Keys**
|
|
78
78
|
>
|
|
79
|
-
> * `id`, `parentId`, `childIds` works on the input item and can be property names or functions.
|
|
79
|
+
> * `id`, `parentId`, `childIds` works on the input item and can be property names or functions. The library does not make any assumption what an id should be so we purposely allow `null` and `undefined` as a valid id too!
|
|
80
80
|
> * `valueKey`, `parentKey`, `childrenKey`, `depthKey` are always strings or `false` and are used as keys in the output nodes.
|
|
81
81
|
|
|
82
|
+
> **'validateReferences' option**
|
|
83
|
+
>
|
|
84
|
+
> Validation operates differently when in `parentId` mode and in `childIds` mode!
|
|
85
|
+
> * in `parentId` mode: validates that the parent ids of root nodes was `null` or `undefined` and nothing else. If you expect these parent ids to be other than `null` or `undefined`, you can safely turn off this validation and loop trough on the roots manually to check the original parentId values are the ones you expect.
|
|
86
|
+
> * in `childIds` mode: validates that every referenced child is resolved. Even if the child list contains `undefined`, a node with an `undefined` as ID must exist in the input.
|
|
87
|
+
|
|
82
88
|
#### Returns
|
|
83
89
|
|
|
84
90
|
```ts
|
package/package.json
CHANGED