treechop: A Lightweight TypeScript Utility for Tree Data Structures

This repository profile is provided by osrepos.com, an open source repository discovery platform.

treechop: A Lightweight TypeScript Utility for Tree Data Structures

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

Analyzed by OSRepos on April 22, 2026

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.

TeamAI-CLI: Empowering Teams to Become AI Native with a Git-Based Foundation

TeamAI-CLI: Empowering Teams to Become AI Native with a Git-Based Foundation

September 24, 2026

TeamAI-CLI, developed by Tencent, is a powerful command-line interface aimed at making every team AI native. It offers a unified, Git-based platform for teams to collaborate, learn, and continuously improve with AI. This tool transforms individual AI capabilities into shared team assets, integrating AI agents, machines, and team members for enhanced efficiency.

TypeScriptAICLI
LLM Wiki: Build a Self-Maintaining, Interlinked Knowledge Base with AI

LLM Wiki: Build a Self-Maintaining, Interlinked Knowledge Base with AI

September 23, 2026

LLM Wiki is a powerful cross-platform desktop application designed to transform your documents into an organized, interlinked knowledge base automatically. Unlike traditional RAG systems, it incrementally builds and maintains a persistent wiki from your sources, ensuring knowledge is compiled once and kept current. This innovative approach offers a dynamic and evolving personal knowledge management solution.

LLMKnowledge BasePersonal Knowledge Management
Maka: A High-Performance Agent Workspace for AI Tasks

Maka: A High-Performance Agent Workspace for AI Tasks

September 21, 2026

Apache Maka (Incubating) is a high-performance agent workspace designed to maintain a complete, append-only record of all agent actions. It focuses on measurable performance, local-first operation, and robust recovery mechanisms. This project provides a unified execution authority for desktop, TUI, and CLI clients, ensuring consistent agent behavior across platforms.

AI AgentAgent RuntimeLLM
OpenMausBot: Your Open-Source AI Bot Team in a Chat App

OpenMausBot: Your Open-Source AI Bot Team in a Chat App

September 20, 2026

OpenMausBot is an open-source desktop application that provides an alternative to Grok Bot, allowing users to manage a team of AI agents within a chat interface. It emphasizes local-first operation, bringing your own agents, and providing each bot with its own virtual machine or access to your computer. This project enables powerful AI interactions with privacy and control at its core.

TypeScriptAIBots

Source repository

Open the original repository on GitHub.

20 counted GitHub visits

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️