Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
tree-node-data
Advanced tools
Readme
tree-node-data
assigns a set of structure meta data for each node in your tree data structure.
Meta data includes parent, prev, prevSibling, next, nextSibling, siblingIndex, ancestors, numDescendants, numChildren.
It is useful for building tree structure UI for data display and data traversal.
npm install tree-node-data
nodeData
field; Original tree node data is intact.In short, it provides a function that assigns an extra field named nodeData
to each node of your tree.
Origin | Result |
---|---|
|
|
Field | Description |
---|---|
parent | key value of parent node |
prevSibling | key value of previous sibling node. null if the current node has no previous sibling node. i.e. it is the first/only child of its parent. |
nextSibling | key value of next sibling node. null if the current node has no next sibling node. i.e. it is the last/only child of its parent. |
prev | key value of previous node. Previous node is defined as previous sibling if found or parent node. |
next | key value of next node. Next node is defined as next sibling node if found. Otherwise, it will be the 'nextSibling' of the closest ancestor that has a 'nextSibling'; |
siblingIndex | The integer index of the current node amongst its siblings. Index starts from 0. |
ancestors | Array of key values of all ancestor nodes. This is useful for working out branch collapsed/expanded status. |
numDescendants | This is the number of leaf nodes. This is useful for showing all items under a branch node. |
numChildren | number of direct child nodes. |
import assignNodeData from 'tree-node-data';
const config = {
childrenField: 'children', // e.g. customise the field for children nodes. e.g. 'subItems', default 'children'
keyField: 'key', // e.g. customise the field for node key. e.g. 'id', default 'key'
};
const nodesWithData = assignNodeData(
nodes, // array of tree nodes.
config,
)
assignNodeData
;tree-node-util
and tree-node-data
together provides the powerful tools for building complex tree data structure UIs;FAQs
Assigns a set of structure meta data for each node in your tree structure useful for tree data display and data traversal
The npm package tree-node-data receives a total of 888 weekly downloads. As such, tree-node-data popularity was classified as not popular.
We found that tree-node-data demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.