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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tr33

v1.1.1

Published

tr33 is a TypeScript library designed to simplify the management of tree structures in your applications. Whether you're dealing with hierarchical data in a frontend framework like React or Vue, or organizing data in a backend service, tr33 provides an in

Readme

tr33

tr33 is a TypeScript library designed to simplify the management of tree structures in your applications. Whether you're dealing with hierarchical data in a frontend framework like React or Vue, or organizing data in a backend service, tr33 provides an intuitive API for creating, manipulating, and traversing tree structures.

Installation You can install tr33 via npm or yarn:

npm install tr33
# or
yarn add tr33

Creating a Tree

To create a tree with tr33, you can use the createTree function. This function takes in either a single RawTreeNode object or an array of RawTreeNode objects and returns a TreeNode or an array of TreeNodes respectively.

import { createTree, RawTreeNode, TreeNode } from 'tr33';

// Define your tree structure
const data: RawTreeNode<number> = {
  value: 1,
  children: [
    {
      value: 2,
      children: [{ value: 3 }, { value: 4 }],
    },
    {
      value: 5,
    },
  ],
};

// Create a tree
const tree: TreeNode<number> = createTree(data) as TreeNode<number>;

console.log(tree.value()); // Output: { id: '...', value: 1, children: [...] }

Manipulating Nodes

You can manipulate nodes in the tree using various methods provided by the TreeNode class.

// Assuming rootNode is a TreeNode instance

// Update the value of a node
rootNode.update(10);

// Add a new child node
rootNode.add({ value: 20 });

// Remove a node by its ID
rootNode.remove('someId');

// Find a node by its ID
const childNode = rootNode.find('someId');

Traversing the Tree

tr33 allows you to traverse the tree easily, whether you need to iterate over all nodes or find a specific node.

// Assuming rootNode is a TreeNode instance

// Get an array of child nodes
const children = rootNode.children();

// Check if a node is a leaf node
const isLeaf = rootNode.isLeaf();

// Find all leaf nodes in the tree
const leafNodes = rootNode.query({}, { isLeaf: true });

// Find the parent nodes of a given node
const parentIds = getNodeParents(rootNode, childNode);

API Reference

createTree(data: RawTreeNode | RawTreeNode[], options?: { createRootNode: boolean }): TreeNode | TreeNode[]: Creates a tree from raw tree node data.

Methods

  • .value(): RawTreeNode<J | null | undefined>: Returns the raw representation of the node.
  • .id(): string: Returns the ID of the node.
  • .update(update: J): TreeNode<NullableVal>: Updates the value of the node.
  • .children(): TreeNode<J>[]: Returns an array of child nodes.
  • .getChildrenValues(): J[]: Returns an array of values of child nodes.
  • .getChildrenIds(): (string | undefined)[]: Returns an array of IDs of child nodes.
  • .add(node: RawTreeNode<J>): string: Adds a child node.
  • .remove(id: string): void: Removes a child node by ID.
  • .find(id: string, acc?: Array<string>): FindResultTuple: Finds a node by its ID.
  • query(query: {}, options: { isLeaf: boolean }, acc?: Array<TreeNode<NullableVal<J>>>): Array<TreeNode<NullableVal<J>>>: Queries the tree for nodes based on a condition.
  • .getParentId(): string | undefined: Returns the ID of the parent node.
  • .isRoot(): boolean: Checks if the node is a root node.
  • .isLeaf(): boolean: Checks if the node is a leaf node.
  • .setId(id: string): Sets the ID of the node.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

Acknowledgments

Thank you to all contributors who have helped make tr33 better.