versatile-tree
Advanced tools
Comparing version 1.1.4 to 1.1.5
{ | ||
"name": "versatile-tree", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"author": "Justin Mahar <contact@justinmahar.com>", | ||
@@ -5,0 +5,0 @@ "description": "A highly versatile tree structure for JavaScript.", |
645
README.md
@@ -36,2 +36,18 @@ <h2 align="center"> | ||
- Construct and use tree structures in JavaScript easily. | ||
- **🔁 Easy conversion to/from JSON** | ||
- Easily convert the entire tree, or a subsection, to and from JSON. | ||
- **🎯 Node paths and selection paths** | ||
- Get a path array to any node, and selection paths for instant selection of nodes. | ||
- **🆔 IDs are optional** | ||
- Versatility is the name of the game. This tree library supports nodes without IDs! | ||
- **👨👩👧👦 Sibling support** | ||
- Get left/right siblings, or add a siblings to any sub-root node. Full sibling support! | ||
- **🔍 Find and walk** | ||
- Find nodes by ID or custom logic, and walk the tree. | ||
- **📄 Deep cloning** | ||
- Easily deep clone the entire tree, or any tree node. | ||
- **🤴 Ancestor and descendent checking** | ||
- Determine if any node is an ancestor or descendant of another. | ||
- **✨ Much more!** | ||
- See the full API below! | ||
@@ -57,50 +73,49 @@ [lock:donate]::🚫--------------------------------------- | ||
- [Quick Start](#quick-start) | ||
- [API](#api) | ||
- [TreeNode / Tree](#treenode--tree) | ||
- [Class Functions](#class-functions) | ||
- [Constructor](#constructor) | ||
- [getData](#getdata) | ||
- [getChildrenPropertyName](#getchildrenpropertyname) | ||
- [hasParent](#hasparent) | ||
- [isRoot](#isroot) | ||
- [equals](#equals) | ||
- [isDescendantOf](#isdescendantof) | ||
- [isAncestorOf](#isancestorof) | ||
- [addChildNode](#addchildnode) | ||
- [addChildData](#addchilddata) | ||
- [getNodePath](#getnodepath) | ||
- [getSelectionPath](#getselectionpath) | ||
- [selectNode](#selectnode) | ||
- [getChildren](#getchildren) | ||
- [hasChildren](#haschildren) | ||
- [getFirstChild](#getfirstchild) | ||
- [getLastChild](#getlastchild) | ||
- [hasChild](#haschild) | ||
- [removeChild](#removechild) | ||
- [removeParent](#removeparent) | ||
- [getSiblings](#getsiblings) | ||
- [getSiblingCount](#getsiblingcount) | ||
- [isOnlyChild](#isonlychild) | ||
- [getFirstSibling](#getfirstsibling) | ||
- [getLastSibling](#getlastsibling) | ||
- [getLeftSibling](#getleftsibling) | ||
- [getRightSibling](#getrightsibling) | ||
- [addSiblingNode](#addsiblingnode) | ||
- [addSiblingData](#addsiblingdata) | ||
- [getIndex](#getindex) | ||
- [indexOfChild](#indexofchild) | ||
- [indexOfSibling](#indexofsibling) | ||
- [getParent](#getparent) | ||
- [isParent](#isparent) | ||
- [setParent](#setparent) | ||
- [getRoot](#getroot) | ||
- [findFirst](#findfirst) | ||
- [findAll](#findall) | ||
- [findById](#findbyid) | ||
- [walk](#walk) | ||
- [toObject](#toobject) | ||
- [toJSON](#tojson) | ||
- [clone](#clone) | ||
- [Static Functions](#static-functions) | ||
- [fromJSON](#fromjson) | ||
- [TreeNode/Tree API](#treenodetree-api) | ||
- [Class Functions](#class-functions) | ||
- [Constructor](#constructor) | ||
- [getData](#getdata) | ||
- [getChildrenPropertyName](#getchildrenpropertyname) | ||
- [hasParent](#hasparent) | ||
- [isRoot](#isroot) | ||
- [equals](#equals) | ||
- [isDescendantOf](#isdescendantof) | ||
- [isAncestorOf](#isancestorof) | ||
- [addChildNode](#addchildnode) | ||
- [addChildData](#addchilddata) | ||
- [getNodePath](#getnodepath) | ||
- [getSelectionPath](#getselectionpath) | ||
- [selectNode](#selectnode) | ||
- [getChildren](#getchildren) | ||
- [hasChildren](#haschildren) | ||
- [getFirstChild](#getfirstchild) | ||
- [getLastChild](#getlastchild) | ||
- [hasChild](#haschild) | ||
- [removeChild](#removechild) | ||
- [removeParent](#removeparent) | ||
- [getSiblings](#getsiblings) | ||
- [getSiblingCount](#getsiblingcount) | ||
- [isOnlyChild](#isonlychild) | ||
- [getFirstSibling](#getfirstsibling) | ||
- [getLastSibling](#getlastsibling) | ||
- [getLeftSibling](#getleftsibling) | ||
- [getRightSibling](#getrightsibling) | ||
- [addSiblingNode](#addsiblingnode) | ||
- [addSiblingData](#addsiblingdata) | ||
- [getIndex](#getindex) | ||
- [indexOfChild](#indexofchild) | ||
- [indexOfSibling](#indexofsibling) | ||
- [getParent](#getparent) | ||
- [isParent](#isparent) | ||
- [setParent](#setparent) | ||
- [getRoot](#getroot) | ||
- [findFirst](#findfirst) | ||
- [findAll](#findall) | ||
- [findById](#findbyid) | ||
- [walk](#walk) | ||
- [toObject](#toobject) | ||
- [toJSON](#tojson) | ||
- [clone](#clone) | ||
- [Static Functions](#static-functions) | ||
- [fromJSON](#fromjson) | ||
- [TypeScript](#typescript) | ||
@@ -135,14 +150,12 @@ - [Icon Attribution](#icon-attribution) | ||
### API | ||
## TreeNode/Tree API | ||
#### TreeNode / Tree | ||
A `Tree` simply extends `TreeNode` and can be used as the root node. Both share the same API, defined below. | ||
##### Class Functions | ||
### Class Functions | ||
###### Constructor | ||
#### Constructor | ||
```ts | ||
new Tree(data: Record<string, any> = {}, options: TreeNodeOptions = TreeNode.defaultTreeNodeOptions) | ||
new TreeNode(data: Record<string, any> = {}, options: TreeNodeOptions = TreeNode.defaultTreeNodeOptions) | ||
``` | ||
@@ -174,8 +187,11 @@ | ||
Params: | ||
- `data` - Optional. An object containing data for the node, plus optional children with subnodes. | ||
- `options` - Optional (pun intended). The options for the TreeNode. Falls back on `TreeNode.defaultTreeNodeOptions` when not specified. | ||
| Param | Description | | ||
| --------- | -------------------------------------------------------------------------------------------------------------------------- | | ||
| `data` | Optional. An object containing data for the node, plus optional children with subnodes. | | ||
| `options` | Optional (pun intended). The options for the TreeNode. Falls back on `TreeNode.defaultTreeNodeOptions` when not specified. | | ||
###### getData | ||
--- | ||
#### getData | ||
```ts | ||
@@ -189,7 +205,10 @@ getData() | ||
Returns: | ||
- The data for this node, without the children property. | ||
| Returns | | ||
| ------------------------------------------------------ | | ||
| The data for this node, without the children property. | | ||
###### getChildrenPropertyName | ||
--- | ||
#### getChildrenPropertyName | ||
```ts | ||
@@ -200,7 +219,10 @@ getChildrenPropertyName() | ||
Returns: | ||
- The property name used for children. | ||
| Returns | | ||
| ------------------------------------ | | ||
| The property name used for children. | | ||
###### hasParent | ||
--- | ||
#### hasParent | ||
```ts | ||
@@ -214,7 +236,10 @@ hasParent(): boolean | ||
Returns: | ||
- True if this node has a parent, false otherwise. | ||
| Returns | | ||
| ------------------------------------------------ | | ||
| True if this node has a parent, false otherwise. | | ||
###### isRoot | ||
--- | ||
#### isRoot | ||
```ts | ||
@@ -227,7 +252,10 @@ isRoot(): boolean | ||
Returns: | ||
- True if this node is the root (has no parent), false otherwise. | ||
| Returns | | ||
| --------------------------------------------------------------- | | ||
| True if this node is the root (has no parent), false otherwise. | | ||
###### equals | ||
--- | ||
#### equals | ||
```ts | ||
@@ -241,9 +269,14 @@ equals(node: TreeNode): boolean | ||
Params: | ||
- `node` - The node to check for equality. | ||
Returns: | ||
- True if the provided node is equal to this node. | ||
| Param | Description | | ||
| ------ | ------------------------------- | | ||
| `node` | The node to check for equality. | | ||
###### isDescendantOf | ||
| Returns | | ||
| ------------------------------------------------ | | ||
| True if the provided node is equal to this node. | | ||
--- | ||
#### isDescendantOf | ||
```ts | ||
@@ -255,10 +288,14 @@ isDescendantOf(node: TreeNode) | ||
Params: | ||
- `node` - The node to check. | ||
| Param | Description | | ||
| ------ | ------------------ | | ||
| `node` | The node to check. | | ||
Returns: | ||
- True if this node is a descendant of, or below, the provided node. False otherwise. | ||
| Returns | | ||
| ----------------------------------------------------------------------------------- | | ||
| True if this node is a descendant of, or below, the provided node. False otherwise. | | ||
###### isAncestorOf | ||
--- | ||
#### isAncestorOf | ||
```ts | ||
@@ -269,10 +306,14 @@ isAncestorOf(node: TreeNode) | ||
Params: | ||
- `node` - The node to check. | ||
- | ||
Returns: | ||
- True if this node is an ancestor of, or above, the provided node. False otherwise. | ||
| Param | Description | | ||
| ------ | ------------------ | | ||
| `node` | The node to check. | | ||
###### addChildNode | ||
| Returns | | ||
| ---------------------------------------------------------------------------------- | | ||
| True if this node is an ancestor of, or above, the provided node. False otherwise. | | ||
--- | ||
#### addChildNode | ||
```ts | ||
@@ -290,9 +331,12 @@ addChildNode(node: TreeNode, index?: number, allowCircularReferences?: boolean) | ||
Params: | ||
- `node` - The node to add as a child. | ||
- `index` - Optional. The index at which to insert the child. If `undefined`, the child will be added to the end. | ||
- `allowCircularReferences` - Optional. Set to `true` to allow circular references. | ||
| Param | Description | | ||
| ------------------------- | ----------------------------------------------------------------------------------------------------- | | ||
| `node` | The node to add as a child. | | ||
| `index` | Optional. The index at which to insert the child. If `undefined`, the child will be added to the end. | | ||
| `allowCircularReferences` | Optional. Set to `true` to allow circular references. | | ||
###### addChildData | ||
--- | ||
#### addChildData | ||
```ts | ||
@@ -303,12 +347,15 @@ addChildData(data: Record<string, any> = {}, index?: number): TreeNode | ||
Params: | ||
- `data` - The child data. A new node will be created from this data. | ||
Params: | ||
- `index` - The index at which to add the child. Pass `undefined` to add to the end of the children. | ||
| Param | Description | | ||
| ------- | ---------------------------------------------------------------------------------------- | | ||
| `data` | The child data. A new node will be created from this data. | | ||
| `index` | The index at which to add the child. Pass `undefined` to add to the end of the children. | | ||
Returns: | ||
- The newly created TreeNode. | ||
| Returns | | ||
| --------------------------- | | ||
| The newly created TreeNode. | | ||
###### getNodePath | ||
--- | ||
#### getNodePath | ||
```ts | ||
@@ -320,7 +367,10 @@ getNodePath(): TreeNode[] | ||
Returns: | ||
- An array containing all nodes in the tree leading to this one, starting with the root. | ||
| Returns | | ||
| -------------------------------------------------------------------------------------- | | ||
| An array containing all nodes in the tree leading to this one, starting with the root. | | ||
###### getSelectionPath | ||
--- | ||
#### getSelectionPath | ||
```ts | ||
@@ -360,7 +410,10 @@ getSelectionPath(): number[] | ||
Returns: | ||
- An array of sibling index positions of all nodes leading to this one. | ||
| Returns | | ||
| --------------------------------------------------------------------- | | ||
| An array of sibling index positions of all nodes leading to this one. | | ||
###### selectNode | ||
--- | ||
#### selectNode | ||
```ts | ||
@@ -381,10 +434,14 @@ selectNode(selectionPath: number[]): TreeNode | undefined | ||
Params: | ||
- `selectionPath` - The selection path for the TreeNode as an array of sibling indexes leading to the desired node. | ||
| Param | Description | | ||
| --------------- | ----------------------------------------------------------------------------------------------- | | ||
| `selectionPath` | The selection path for the TreeNode as an array of sibling indexes leading to the desired node. | | ||
Returns: | ||
- The selected TreeNode, or `undefined` if not found. | ||
| Returns | | ||
| --------------------------------------------------- | | ||
| The selected TreeNode, or `undefined` if not found. | | ||
###### getChildren | ||
--- | ||
#### getChildren | ||
```ts | ||
@@ -395,7 +452,10 @@ getChildren(): TreeNode[] | ||
Returns: | ||
- The children for this node. | ||
| Returns | | ||
| --------------------------- | | ||
| The children for this node. | | ||
###### hasChildren | ||
--- | ||
#### hasChildren | ||
```ts | ||
@@ -406,7 +466,10 @@ hasChildren(): boolean | ||
Returns: | ||
- True if this node has children. False otherwise. | ||
| Returns | | ||
| ------------------------------------------------ | | ||
| True if this node has children. False otherwise. | | ||
###### getFirstChild | ||
--- | ||
#### getFirstChild | ||
```ts | ||
@@ -418,7 +481,10 @@ getFirstChild(): TreeNode | undefined | ||
Returns: | ||
- The first child in this node's list of children, or `undefined` if there are no children. | ||
| Returns | | ||
| ----------------------------------------------------------------------------------------- | | ||
| The first child in this node's list of children, or `undefined` if there are no children. | | ||
###### getLastChild | ||
--- | ||
#### getLastChild | ||
```ts | ||
@@ -430,7 +496,10 @@ getLastChild(): TreeNode | undefined | ||
Returns: | ||
- The last child in this node's list of children, or `undefined` if there are no children. | ||
| Returns | | ||
| ---------------------------------------------------------------------------------------- | | ||
| The last child in this node's list of children, or `undefined` if there are no children. | | ||
###### hasChild | ||
--- | ||
#### hasChild | ||
```ts | ||
@@ -444,10 +513,14 @@ hasChild(node: TreeNode) | ||
Params: | ||
- `node` - The node to search for. | ||
| Param | Description | | ||
| ------ | ----------------------- | | ||
| `node` | The node to search for. | | ||
Returns: | ||
- True if this node has the provided node in its direct list of children. False otherwise. | ||
| Returns | | ||
| ---------------------------------------------------------------------------------------- | | ||
| True if this node has the provided node in its direct list of children. False otherwise. | | ||
###### removeChild | ||
--- | ||
#### removeChild | ||
```ts | ||
@@ -462,10 +535,14 @@ removeChild(node: TreeNode): boolean | ||
Params: | ||
- `node` - The node to remove. | ||
| Param | Description | | ||
| ------ | ------------------- | | ||
| `node` | The node to remove. | | ||
Returns: | ||
- True if the node was removed. False if it was not found. | ||
| Returns | | ||
| -------------------------------------------------------- | | ||
| True if the node was removed. False if it was not found. | | ||
###### removeParent | ||
--- | ||
#### removeParent | ||
```ts | ||
@@ -480,7 +557,10 @@ removeParent(): boolean | ||
Returns: | ||
- True if this node was removed from its parent, false otherwise. | ||
| Returns | | ||
| --------------------------------------------------------------- | | ||
| True if this node was removed from its parent, false otherwise. | | ||
###### getSiblings | ||
--- | ||
#### getSiblings | ||
```ts | ||
@@ -491,7 +571,10 @@ getSiblings(): TreeNode[] | ||
Returns: | ||
- An array of all siblings for this node. | ||
| Returns | | ||
| --------------------------------------- | | ||
| An array of all siblings for this node. | | ||
###### getSiblingCount | ||
--- | ||
#### getSiblingCount | ||
```ts | ||
@@ -503,7 +586,10 @@ getSiblingCount(): number | ||
Returns: | ||
- The number of siblings this node has including itself. | ||
| Returns | | ||
| ------------------------------------------------------ | | ||
| The number of siblings this node has including itself. | | ||
###### isOnlyChild | ||
--- | ||
#### isOnlyChild | ||
```ts | ||
@@ -515,7 +601,10 @@ isOnlyChild(): boolean | ||
Returns: | ||
- True if this node is an only child (has no other siblings), false otherwise. | ||
| Returns | | ||
| ---------------------------------------------------------------------------- | | ||
| True if this node is an only child (has no other siblings), false otherwise. | | ||
###### getFirstSibling | ||
--- | ||
#### getFirstSibling | ||
```ts | ||
@@ -527,7 +616,10 @@ getFirstSibling(): TreeNode | ||
Returns: | ||
- The first sibling in this node's list of siblings. | ||
| Returns | | ||
| -------------------------------------------------- | | ||
| The first sibling in this node's list of siblings. | | ||
###### getLastSibling | ||
--- | ||
#### getLastSibling | ||
```ts | ||
@@ -539,7 +631,10 @@ getLastSibling(): TreeNode | ||
Returns: | ||
- The last sibling in this node's list of siblings. | ||
| Returns | | ||
| ------------------------------------------------- | | ||
| The last sibling in this node's list of siblings. | | ||
###### getLeftSibling | ||
--- | ||
#### getLeftSibling | ||
```ts | ||
@@ -551,7 +646,10 @@ getLeftSibling(): TreeNode | undefined | ||
Returns: | ||
- The sibling to the left of this node, or `undefined` if there is none. | ||
| Returns | | ||
| ---------------------------------------------------------------------- | | ||
| The sibling to the left of this node, or `undefined` if there is none. | | ||
###### getRightSibling | ||
--- | ||
#### getRightSibling | ||
```ts | ||
@@ -562,7 +660,10 @@ getRightSibling(): TreeNode | undefined | ||
Returns: | ||
- The sibling to the right of this node, or `undefined` if there is none. | ||
| Returns | | ||
| ----------------------------------------------------------------------- | | ||
| The sibling to the right of this node, or `undefined` if there is none. | | ||
###### addSiblingNode | ||
--- | ||
#### addSiblingNode | ||
```ts | ||
@@ -577,11 +678,15 @@ addSiblingNode(node: TreeNode, index?: number) | ||
Params: | ||
- `node` - The node to add as a sibling. | ||
- `index` - Optional. The index for the new sibling. | ||
| Param | Description | | ||
| ------- | ---------------------------------------- | | ||
| `node` | The node to add as a sibling. | | ||
| `index` | Optional. The index for the new sibling. | | ||
Errors thrown: | ||
- Throws an error if called at the root. | ||
| Errors Thrown | | ||
| -------------------------------------- | | ||
| Throws an error if called at the root. | | ||
###### addSiblingData | ||
--- | ||
#### addSiblingData | ||
```ts | ||
@@ -597,11 +702,15 @@ addSiblingData(data: Record<string, any> = {}, index?: number): TreeNode | ||
Params: | ||
- `data` - The sibling data. A new node will be created from this data. | ||
- `index` - The index at which to add the sibling. Pass `undefined` to add to the end of the siblings. | ||
| Param | Description | | ||
| ------- | ------------------------------------------------------------------------------------------ | | ||
| `data` | The sibling data. A new node will be created from this data. | | ||
| `index` | The index at which to add the sibling. Pass `undefined` to add to the end of the siblings. | | ||
Returns: | ||
- The newly created TreeNode. | ||
| Returns | | ||
| --------------------------- | | ||
| The newly created TreeNode. | | ||
###### getIndex | ||
--- | ||
#### getIndex | ||
```ts | ||
@@ -614,7 +723,10 @@ getIndex(): number | ||
Returns: | ||
- This node's index among its siblings. | ||
| Returns | | ||
| ------------------------------------- | | ||
| This node's index among its siblings. | | ||
###### indexOfChild | ||
--- | ||
#### indexOfChild | ||
```ts | ||
@@ -626,10 +738,14 @@ indexOfChild(node: TreeNode): number | ||
Params: | ||
- `node` - The node for which to find the index in this node's list of children. | ||
| Param | Description | | ||
| ------ | --------------------------------------------------------------------- | | ||
| `node` | The node for which to find the index in this node's list of children. | | ||
Returns: | ||
- The index of the provided node in this node's list of children, or `-1` if it is not found. | ||
| Returns | | ||
| ------------------------------------------------------------------------------------------- | | ||
| The index of the provided node in this node's list of children, or `-1` if it is not found. | | ||
###### indexOfSibling | ||
--- | ||
#### indexOfSibling | ||
```ts | ||
@@ -641,10 +757,14 @@ indexOfSibling(node: TreeNode): number | ||
Params: | ||
- `node` - The node for which to find the index in this node's list of siblings. | ||
| Param | Description | | ||
| ------ | --------------------------------------------------------------------- | | ||
| `node` | The node for which to find the index in this node's list of siblings. | | ||
Returns: | ||
- The index of the provided node in this node's list of siblings, or `-1` if it is not found. | ||
| Returns | | ||
| ------------------------------------------------------------------------------------------- | | ||
| The index of the provided node in this node's list of siblings, or `-1` if it is not found. | | ||
###### getParent | ||
--- | ||
#### getParent | ||
```ts | ||
@@ -655,7 +775,10 @@ getParent(): TreeNode | undefined | ||
Returns: | ||
- The parent of this node, or `undefined` if there is none. | ||
| Returns | | ||
| --------------------------------------------------------- | | ||
| The parent of this node, or `undefined` if there is none. | | ||
###### isParent | ||
--- | ||
#### isParent | ||
```ts | ||
@@ -668,10 +791,14 @@ isParent(node: TreeNode) | ||
Params: | ||
- `node` - The node to check. | ||
| Param | Description | | ||
| ------ | ------------------ | | ||
| `node` | The node to check. | | ||
Returns: | ||
- True if the provided node is this node's direct parent, false otherwise. | ||
| Returns | | ||
| ------------------------------------------------------------------------ | | ||
| True if the provided node is this node's direct parent, false otherwise. | | ||
###### setParent | ||
--- | ||
#### setParent | ||
```ts | ||
@@ -682,7 +809,10 @@ setParent(parent: TreeNode | undefined): void | ||
Params: | ||
- `parent` - The node to set as the new parent. | ||
| Param | Description | | ||
| -------- | ---------------------------------- | | ||
| `parent` | The node to set as the new parent. | | ||
###### getRoot | ||
--- | ||
#### getRoot | ||
```ts | ||
@@ -694,7 +824,10 @@ getRoot(): TreeNode | ||
Returns: | ||
- The root node at the top of the tree hierarchy. | ||
| Returns | | ||
| ----------------------------------------------- | | ||
| The root node at the top of the tree hierarchy. | | ||
###### findFirst | ||
--- | ||
#### findFirst | ||
```ts | ||
@@ -711,11 +844,15 @@ findFirst(predicate: (node: TreeNode) => boolean, rightToLeft?: boolean): TreeNode | undefined | ||
Params: | ||
- `predicate` - A function used to match the node being searched for. This function is passed a node and returns true if the node is a match. | ||
- `rightToLeft` - Optional. When true, searching will traverse the tree using depth-first right-to-left preorder traversal. | ||
| Param | Description | | ||
| ------------- | ----------------------------------------------------------------------------------------------------------------------------- | | ||
| `predicate` | A function used to match the node being searched for. This function is passed a node and returns true if the node is a match. | | ||
| `rightToLeft` | Optional. When true, searching will traverse the tree using depth-first right-to-left preorder traversal. | | ||
Returns: | ||
- The found node, or `undefined` if not found. | ||
| Returns | | ||
| -------------------------------------------- | | ||
| The found node, or `undefined` if not found. | | ||
###### findAll | ||
--- | ||
#### findAll | ||
```ts | ||
@@ -732,11 +869,15 @@ findAll(predicate: (node: TreeNode) => boolean, rightToLeft?: boolean): TreeNode[] | ||
Params: | ||
- `predicate` - A function used to match the nodes being searched for. This function is passed a node and returns true if the node is a match. | ||
- `rightToLeft` - Optional. When true, searching will traverse the tree using depth-first right-to-left preorder traversal. | ||
| Param | Description | | ||
| ------------- | ------------------------------------------------------------------------------------------------------------------------------ | | ||
| `predicate` | A function used to match the nodes being searched for. This function is passed a node and returns true if the node is a match. | | ||
| `rightToLeft` | Optional. When true, searching will traverse the tree using depth-first right-to-left preorder traversal. | | ||
Returns: | ||
- A `TreeNode[]` array containing all found nodes. | ||
| Returns | | ||
| ------------------------------------------------ | | ||
| A `TreeNode[]` array containing all found nodes. | | ||
###### findById | ||
--- | ||
#### findById | ||
```ts | ||
@@ -754,12 +895,16 @@ findById(id: any, idPropertyName = 'id', rightToLeft?: boolean): TreeNode | undefined | ||
Params: | ||
- `id` - The node ID to search for. | ||
- `idPropertyName` - Optional. The property name of the ID. Defaults as "id". | ||
- `rightToLeft` - Optional. When true, searching will traverse the tree using depth-first right-to-left preorder traversal. | ||
| Param | Description | | ||
| ---------------- | --------------------------------------------------------------------------------------------------------- | | ||
| `id` | The node ID to search for. | | ||
| `idPropertyName` | Optional. The property name of the ID. Defaults as "id". | | ||
| `rightToLeft` | Optional. When true, searching will traverse the tree using depth-first right-to-left preorder traversal. | | ||
Returns: | ||
- The node with the provided id, or `undefined` if not found. | ||
| Returns | | ||
| ----------------------------------------------------------- | | ||
| The node with the provided id, or `undefined` if not found. | | ||
###### walk | ||
--- | ||
#### walk | ||
```ts | ||
@@ -776,11 +921,15 @@ walk(visit: (node: TreeNode) => boolean | void, rightToLeft?: boolean): boolean | ||
Params: | ||
- `visit` - A visit function called on every node traversed. If the visit function returns true at any point, walking is aborted. | ||
- `rightToLeft` - Optional. When true, it will traverse the tree using depth-first right-to-left preorder traversal. | ||
| Param | Description | | ||
| ------------- | --------------------------------------------------------------------------------------------------------------------- | | ||
| `visit` | A visit function called on every node traversed. If the visit function returns true at any point, walking is aborted. | | ||
| `rightToLeft` | Optional. When true, it will traverse the tree using depth-first right-to-left preorder traversal. | | ||
Returns: | ||
- True if the traversal was aborted, false otherwise. | ||
| Returns | | ||
| --------------------------------------------------- | | ||
| True if the traversal was aborted, false otherwise. | | ||
###### toObject | ||
--- | ||
#### toObject | ||
```ts | ||
@@ -794,7 +943,10 @@ toObject(): Record<string, any> | ||
Returns: | ||
- An object containing the tree node data including all nested children. | ||
| Returns | | ||
| ---------------------------------------------------------------------- | | ||
| An object containing the tree node data including all nested children. | | ||
###### toJSON | ||
--- | ||
#### toJSON | ||
```ts | ||
@@ -813,10 +965,14 @@ toJSON(): string | ||
Returns: | ||
- A JSON string of an object containing the tree node data including all nested children. | ||
| Returns | | ||
| --------------------------------------------------------------------------------------- | | ||
| A JSON string of an object containing the tree node data including all nested children. | | ||
Errors thrown: | ||
- An error if the tree node data cannot be converted to a string using `JSON.stringify()`. | ||
| Errors Thrown | | ||
| ---------------------------------------------------------------------------------------- | | ||
| An error if the tree node data cannot be converted to a string using `JSON.stringify()`. | | ||
###### clone | ||
--- | ||
#### clone | ||
```ts | ||
@@ -831,11 +987,13 @@ clone(): TreeNode | ||
Returns: | ||
- A deep clone of the tree node, including all children. | ||
| Returns | | ||
| ------------------------------------------------------ | | ||
| A deep clone of the tree node, including all children. | | ||
Errors thrown: | ||
- An error if `JSON.stringify()` fails on the tree node. | ||
| Errors Thrown | | ||
| ------------------------------------------------------ | | ||
| An error if `JSON.stringify()` fails on the tree node. | | ||
##### Static Functions | ||
### Static Functions | ||
###### fromJSON | ||
#### fromJSON | ||
@@ -857,16 +1015,17 @@ ```ts | ||
Params: | ||
- `dataString` - The JSON data string containing an object with nested children. | ||
- `options` - Optional. The options for the TreeNode. | ||
| Param | Description | | ||
| ------------ | --------------------------------------------------------------- | | ||
| `dataString` | The JSON data string containing an object with nested children. | | ||
| `options` | Optional. The options for the TreeNode. | | ||
Returns: | ||
- A TreeNode constructed from the parsed JSON. | ||
| Returns | | ||
| -------------------------------------------- | | ||
| A TreeNode constructed from the parsed JSON. | | ||
Errors thrown: | ||
- An error if JSON parsing fails. | ||
| Errors Thrown | | ||
| ------------------------------- | | ||
| An error if JSON parsing fails. | | ||
--- | ||
[lock:typescript]::🚫--------------------------------------- | ||
@@ -873,0 +1032,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
178324
1018