fast-tree-builder 2.0.0-alpha.0 → 2.0.0-alpha.1
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 +16 -16
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,30 +6,30 @@
|
|
|
6
6
|
[](https://coveralls.io/github/lionel87/fast-tree-builder?branch=master)
|
|
7
7
|

|
|
8
8
|
|
|
9
|
-
`fast-tree-builder` is a
|
|
9
|
+
`fast-tree-builder` is a utility for easy tree building from iterable collections, enabling safe and predictable access to hierarchical data. It supports highly customizable input and output shapes.
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
## Prerequisites
|
|
13
13
|
|
|
14
14
|
- You have a list of items,
|
|
15
15
|
- each item is identifiable by a unique id,
|
|
16
|
-
- the items are connected via a *parent id* OR *
|
|
16
|
+
- the items are connected via a *parent id* OR *child ids*.
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
## Features
|
|
20
20
|
|
|
21
|
-
- **
|
|
22
|
-
- **
|
|
23
|
-
- **
|
|
24
|
-
- **
|
|
25
|
-
- **
|
|
26
|
-
- **
|
|
21
|
+
- **Supports `parentId` and `childIds` Models** – Choose your relation style via options.
|
|
22
|
+
- **Fully Typed** – TypeScript support with correct types for the built tree.
|
|
23
|
+
- **Highly Customizable** – Design the node structure as you like.
|
|
24
|
+
- **Any Iterable Accepted** – Works on arrays, sets, or any iterable type.
|
|
25
|
+
- **Flexible ID Types** – Anything can be an identifier; relations matched with `childId === parentId`.
|
|
26
|
+
- **Efficient Tree Construction** – Builds trees from unordered data in O(n) time.
|
|
27
27
|
- **Bi-Directional Tree Links** – Nodes can store both `children` and `parent` references.
|
|
28
|
-
- **Multi-Root Support** – Handles disjoint trees naturally
|
|
29
|
-
- **
|
|
28
|
+
- **Multi-Root Support** – Handles disjoint trees naturally.
|
|
29
|
+
- **Arbitary Node Access** – Returns a `Map` that allows constant-time access to any node.
|
|
30
30
|
- **Tree Validation** – Detects cycles or nodes reachable through multiple paths.
|
|
31
31
|
- **Reference Validation** – Optionally enforce that all parent/child links are valid.
|
|
32
|
-
|
|
32
|
+
- **Depth Values** – Optionally includes a depth value in each node.
|
|
33
33
|
|
|
34
34
|
## Installation
|
|
35
35
|
|
|
@@ -61,8 +61,8 @@ Builds a tree structure from an iterable list of items.
|
|
|
61
61
|
|
|
62
62
|
##### One of:
|
|
63
63
|
|
|
64
|
-
- `parentId`: A key or function
|
|
65
|
-
- `childIds`: A key or function
|
|
64
|
+
- `parentId`: A key or function that access the parent ID of the item.
|
|
65
|
+
- `childIds`: A key or function that access an iterable of child IDs for the item.
|
|
66
66
|
|
|
67
67
|
##### Optional
|
|
68
68
|
|
|
@@ -78,15 +78,15 @@ Builds a tree structure from an iterable list of items.
|
|
|
78
78
|
|
|
79
79
|
```ts
|
|
80
80
|
{
|
|
81
|
-
roots: TreeNode[],
|
|
82
|
-
nodes: Map<id, TreeNode>
|
|
81
|
+
roots: TreeNode[], // top-level nodes
|
|
82
|
+
nodes: Map<id, TreeNode> // all nodes by id
|
|
83
83
|
}
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
#### Throws
|
|
87
87
|
|
|
88
88
|
- Missing required `id`, `parentId`/`childIds`, or `options` parameter
|
|
89
|
-
- Duplicate item identifiers
|
|
89
|
+
- Duplicate item identifiers in input
|
|
90
90
|
- Invalid reference (if `validateReferences` is enabled)
|
|
91
91
|
- Cycle or structural error (if `validateTree` or `withDepth` is enabled)
|
|
92
92
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-tree-builder",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"description": "Easily construct highly customizable bi-directional tree structures from iterable data.",
|
|
5
5
|
"types": "./index.d.mts",
|
|
6
6
|
"module": "./index.mjs",
|
|
7
7
|
"main": "./index.cjs",
|