Our take
- Activity
- 35
- Community
- 4
- Issues
- 21
- Pull requests
- 21
+0 stars in the last 8 days
- Fewer contributors than 92% of the projects we track
Overview
treechop provides functions for working with nested tree data and flat arrays of nodes linked by parent references. It covers common tasks such as traversal, searching, filtering, mapping, sorting, and conversion between representations.
It is suited to TypeScript and JavaScript projects that handle hierarchical data and want reusable operations rather than implementing each traversal themselves. Options allow callers to configure node keys and traversal order, while callbacks can receive metadata such as depth and parent nodes.
Key Features
- Traverse nodes using pre-order, post-order, or breadth-first strategies.
- Find, count, or test for nodes matching a predicate.
- Filter into a flat list or a tree, and search while retaining relevant branches.
- Map nodes into flat results or a transformed tree.
- Delete matching nodes while returning a tree result.
- Convert between nested trees and flat arrays with parent references.
- Sort nodes at each tree level by a selected key.
- Configure keys such as children, ID, and parent fields through options.
Use Cases
- TypeScript application developers can process nested menus, categories, or organizational structures without writing repeated traversal logic.
- Data-interface developers can filter a hierarchy for a search result while preserving its tree structure.
- Developers working with APIs that return parent-linked flat records can convert them into nested trees for presentation or processing.
- Teams transforming hierarchical records can map nodes while retaining structure, or flatten trees for downstream operations.
Getting Started
Install from npm:
npm install treechop
See the repository README for function signatures and examples.
Considerations
The repository describes a focused utility library, not a tree UI or data store. The provided information does not specify runtime requirements or compatibility guarantees. The repository has 6 stars and 1 fork, so evaluate its API and maintenance fit for your project before relying on it for critical workloads.
Found this useful?
Share it with someone who would like treechop.