npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

flextree

v3.2.1

Published

Tree storage library based on left-right value algorithm

Downloads

887

Readme

FlexTree

NPM Version License: MIT TypeScript Coverage

FlexTree is a powerful tree structure storage and management library based on the Nested Set Model (Left-Right Value Algorithm). It provides efficient tree operations, supports multiple databases, and is built with TypeScript for complete type safety.

🌟 Features

Core Capabilities

  • 🚀 High Performance: Based on Nested Set Model for efficient tree queries and operations
  • 💪 Database Agnostic: Support for SQLite, MySQL, PostgreSQL, Oracle, SQL Server
  • 🔷 TypeScript-First: Complete type definitions and generic support for type safety
  • 🔄 Transaction Support: Built-in transaction management for data integrity
  • 🎯 Singleton Pattern: Optional singleton mode for optimized resource usage
  • 🛡️ Concurrent Safety: AsyncLocalStorage-based context isolation prevents dirty reads

Advanced Features

  • 🗑️ Recycle Bin: Logical deletion with restore capability via recyclebin configuration
  • 📋 Node Copying: Copy nodes with optional descendants and field filtering
  • 🌲 Cross-Tree Operations: Move nodes between different trees seamlessly
  • 👥 Multi-Root Trees: Support for trees with multiple top-level nodes
  • 🔍 Tree Traversal: DFS/BFS traversal with interruption support
  • 🔧 Tree Repair: Automatic repair of corrupted tree structures
  • 📊 Node Events: Event system for node lifecycle monitoring
  • 📤 Export Options: Export to JSON (nested) or flat list formats

Developer Experience

  • ✅ 95%+ Test Coverage: Comprehensive test suite ensures reliability
  • 📝 Extensive Documentation: Detailed guides and API documentation
  • 🔌 Flexible Adapters: Easy database adapter integration
  • 🎨 Mixin Architecture: Modular design for extensibility

📦 Installation

# Core package
npm install flextree

# SQLite adapter
npm install flextree-sqlite-adapter

# Prisma adapter
npm install flextree-prisma-adapter

# Bun SQLite adapter
npm install flextree-bun-sqlite-adapter

# SQL.js adapter (browser support)
npm install flextree-sqljs-adapter

🚀 Quick Start

1. Database Setup

Create a table with the required fields:

CREATE TABLE your_table (
    id INTEGER PRIMARY KEY,
    name VARCHAR,
    level INTEGER,
    leftValue INTEGER,
    rightValue INTEGER
);

2. Initialize FlexTreeManager

import { FlexTreeManager } from 'flextree';
import SqliteAdapter from 'flextree-sqlite-adapter';

const adapter = new SqliteAdapter('database.db');
await adapter.open();

const manager = new FlexTreeManager('your_table', {
    adapter: adapter
});

3. Create and Manipulate Trees

// Create root node
await manager.createRoot({ name: 'Root' });

// Add child nodes
await manager.addNodes([
    { name: 'Child 1' },
    { name: 'Child 2' }
]);

// Query nodes
const root = await manager.getRoot();
const children = await manager.getChildren(root);

// Move nodes
await manager.move(childNode, parentNode);

// Delete nodes
await manager.deleteNode(node);

📚 Documentation

For comprehensive guides, API references, and advanced usage, visit our documentation site:

Key Documentation Sections

🔧 Advanced Usage

Singleton Pattern

// Get singleton instance
const manager = FlexTreeManager.getInstance('table_name', options);

// Clear singleton cache
FlexTreeManager.clearInstance('table_name');

Recycle Bin

// Soft delete with recycle bin
await manager.deleteNode(node, { recycle: true });

// Clear recycle bin
await manager.clearRecycleBin();

Tree Export

// Export to nested JSON
const jsonTree = await manager.toJson();

// Export to flat list
const flatList = await manager.toList();

Event System

manager.on('node:added', (node) => {
    console.log('Node added:', node);
});

manager.on('node:moved', (node) => {
    console.log('Node moved:', node);
});

🧪 Testing

# Run all tests
bun test

# Generate coverage report
bun run coverage

# Run specific package tests
bun --filter flextree test

📄 License

MIT © wxzhang

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

🔗 Related Projects

📞 Support

For issues, questions, or contributions, please visit our GitHub repository.