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.

Pi Agent Harness: An AI Agent Toolkit for LLMs and Coding
August 10, 2026
Pi Agent Harness is a comprehensive AI agent toolkit designed for building and deploying intelligent agents. It features a unified API for various Large Language Models, a robust agent runtime with tool calling, and an interactive coding agent CLI. This project provides a modular and extensible foundation for developing advanced AI applications.

background-agents: An Open-Source System for Background Coding Agents
August 10, 2026
background-agents is an open-source system designed for running background coding agents. It enables developers to automate tasks, collaborate in real-time, and integrate with various platforms like GitHub, Slack, and Linear. With support for multiple AI models and full development environments, it streamlines development workflows and enhances productivity.

Clowder AI: Orchestrating AI Teams for Collaborative Development
August 10, 2026
Clowder AI is an innovative platform designed to transform isolated AI agents into cohesive, collaborative teams. It emphasizes persistent identity, cross-model review, and shared memory, enabling AI models like Claude, GPT, and Gemini to work together seamlessly. This platform empowers users to orchestrate AI workflows, fostering a new paradigm for AI-driven development and co-creation.

LobeHub: Your Chief Agent Operator for AI Team Orchestration
August 8, 2026
LobeHub acts as a Chief Agent Operator, streamlining the management of your AI team. It enables hiring, scheduling, and reporting on agents for 24/7 operations, allowing users to maintain control without constant online presence. This platform transforms individual AI tools into a cohesive, productive team.
Source repository
Open the original repository on GitHub.
14 counted GitHub visits