treechop: A Lightweight TypeScript Utility for Tree Data Structures
This repository profile is provided by osrepos.com, an open source repository discovery platform.
Summary
treechop is a lightweight TypeScript utility library designed to simplify working with tree data structures in JavaScript and TypeScript projects. It offers a comprehensive set of common operations, including counting, deleting, filtering, mapping, and converting between flat arrays and tree formats. Developers can efficiently manage hierarchical data with customizable options for keys and traversal strategies.
Repository Information
Topics
Click on any tag to explore related repositories
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
treechop is a powerful, lightweight TypeScript utility library specifically crafted for handling tree data structures. It provides a comprehensive suite of functions to perform common operations such as traversal, manipulation, and conversion of hierarchical data. With treechop, developers can easily count nodes, delete specific branches, filter elements, map values, and transform data between flat arrays and nested tree formats, all while offering flexible customization options for keys and traversal methods.
Installation
To integrate treechop into your project, use npm or yarn:
npm install treechop
# or
yarn add treechop
Examples
treechop offers a wide range of functions to manage your tree data. Here are a few examples demonstrating its versatility:
Counting Nodes:
import { treeCount } from 'treechop';
const tree = [
{ id: 1, value: 10, children: [{ id: 2, value: 20 }] },
{ id: 3, value: 30 }
];
const count = treeCount(tree, node => node.value % 10 === 0);
// count will be 3
Deleting Nodes:
import { treeDelete } from 'treechop';
const tree = [
{ id: 1, children: [{ id: 2 }] },
{ id: 3 }
];
const newTree = treeDelete(tree, node => node.id === 2);
// newTree will be [{ id: 1, children: [] }, { id: 3 }]
Converting Flat Array to Tree:
import { treeFromArray } from 'treechop';
const flatNodes = [
{ id: '1', name: 'Node 1' },
{ id: '1-1', name: 'Node 1-1', pid: '1' },
{ id: '2', name: 'Node 2' }
];
const tree = treeFromArray(flatNodes, { idKey: 'id', parentKey: 'pid' });
/*
tree will be:
[
{ id: '1', name: 'Node 1', children: [{ id: '1-1', name: 'Node 1-1', pid: '1' }] },
{ id: '2', name: 'Node 2' }
]
*/
Mapping Tree Nodes:
import { treeMap } from 'treechop';
const tree = [
{ id: 1, name: 'alpha', children: [{ id: 2, name: 'beta' }] }
];
const upperTree = treeMap(tree, node => ({ ...node, name: node.name.toUpperCase() }));
/*
upperTree will be:
[
{ id: 1, name: 'ALPHA', children: [{ id: 2, name: 'BETA' }] }
]
*/
Why Use treechop?
- Lightweight and Efficient: Designed to be minimal and performant for common tree operations.
- Comprehensive Functionality: Offers a rich set of utilities, from basic traversal to complex transformations.
- TypeScript Support: Fully typed, providing excellent developer experience and compile-time safety.
- Customizable: Most methods allow customization of key names (
childrenKey,idKey,parentKey) and traversal strategies (pre,post,breadth), making it adaptable to various tree structures. - Clear API: The functions are intuitive and well-documented, making them easy to learn and use.
Links
Related repositories
Similar repositories that may be relevant next.

Synara: A Local-First Desktop App for AI-Powered Coding
June 17, 2026
Synara is a local-first desktop application designed to streamline coding with various AI agents and subscriptions. It integrates chats, terminals, browser previews, and Git operations into a single focused workspace, eliminating the need to juggle multiple windows. This app empowers developers to leverage their existing AI tools for parallel work across projects while maintaining a private, local environment.

Understand-Anything: Interactive Knowledge Graphs for Codebases
June 15, 2026
Understand-Anything is an innovative open-source project that transforms any codebase or knowledge base into an interactive knowledge graph. It allows developers to visually explore, search, and query their projects, making complex systems easier to comprehend. This tool integrates seamlessly with popular AI coding platforms like Claude Code, Codex, and Copilot.
Cabinet: An AI-First Knowledge Base and Startup OS
June 14, 2026
Cabinet is an AI-first knowledge base and startup OS designed to keep your data local and private. It allows you to build a custom AI team with agents that remember context, manage tasks, and automate workflows. This self-hosted solution ensures your information remains under your control, without vendor lock-in.

Warpchart: Live GitHub Repository Growth Telemetry and Star Ranking
June 14, 2026
Warpchart offers a unique, live growth telemetry dashboard for any GitHub repository. It provides a dynamic star chart, tracking your repo's journey through the worldwide ranking with real-time updates and even sound. This tool transforms raw star data into actionable insights, helping maintainers understand their project's visibility and growth.
Source repository
Open the original repository on GitHub.