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

taproot

v0.4.1

Published

A tree manipulation library.

Readme

taproot

Tree manipulation made easy.

Installation

npm

npm install taproot

web

Simply source the file in a script tag:

<script src='lib/taproot.js'></script>

Usage

Creating nodes

createNode(value, identifier, [parent = null])

Note that you can only have one root node per tree.

tree = new Tree();
tree.createNode('root', 'root');
tree.createNode('1st level', '1a', 'root');
tree.createNode(['value', 'can', 'be', 'anything'], '2a', '1a');
tree.createNode({objects: 'yes'}, '1b', 'root');
tree.createNode('deep nesting', '2b', '1b');

Iterating through the tree

expand([position = tree.root], [mode = 'DEPTH'], [filter = function(identifier) { return true; }])

Supported modes are 'DEPTH' and 'WIDTH'. The result list will be passed through the filter function if one is provided.

tree.expand();

// ["root", "1a", "2a", "1b", "2b"]

tree.expand(tree.root, 'WIDTH');

// ["root", "1a", "1b", "2a", "2b"]

reverse(position, [filter = function() { return true; }])

tree.reverse('2b', function(identifier) { return identifier !== 'root'});

// ["2b", "1b"]

Rendering the tree as an object

toObj([position = tree.root], [nodeKey = 'data'], [childrenKey = 'children'])

tree.toObj();

// {
//   "data": "root",
//   "children": [
//     {
//       "data": "1st level",
//       "children": [
//         {
//           "data": [
//             "value",
//             "can",
//             "be",
//             "anything"
//           ]
//         }
//       ]
//     },
//     {
//       "data": {
//         "objects": "yes"
//       },
//       "children": [
//         {
//           "data": "deep nesting"
//         }
//       ]
//     }
//   ]
// }

Getting a subtree

subTree(position)

subtree = tree.subTree('1a');

// {
//   "data": "1st level",
//   "children": [
//     {
//       "data": [
//         "value",
//         "can",
//         "be",
//         "anything"
//       ]
//     }
//   ]
// }

Removing nodes

Removing a node will also remove all of its children.

removeNode(identifier)

tree.removeNode('1a');

// {
//   "data": "root",
//   "children": [
//     {
//       "data": {
//         "objects": "yes"
//       },
//       "children": [
//         {
//           "data": "deep nesting"
//         }
//       ]
//     }
//   ]
// }

Moving nodes

moveNode(node, destinationParent)

tree.moveNode('2b', 'root');

// {
//   "data": "root",
//   "children": [
//     {
//       "data": {
//         "objects": "yes"
//       }
//     },
//     {
//       "data": "deep nesting"
//     }
//   ]
// }

Transplanting a tree

transplant(destinationParent, newTree)

tree = new Tree();
tree.createNode('root', 'root');
tree.createNode('1st level', '1', 'root');
tree.createNode('2nd level', '2', '1');

newTree = new Tree();
newTree.createNode('root', 'rootn');
newTree.createNode('1st level new', '1n', 'rootn');
newTree.createNode('2nd level new', '2n', '1n');

tree.transplant('1', newTree);

// {
//   "data": "root",
//   "children": [
//     {
//       "data": "1st level",
//       "children": [
//         {
//           "data": "2nd level"
//         },
//         {
//           "data": "root",
//           "children": [
//             {
//               "data": "1st level new",
//               "children": [
//                 {
//                   "data": "2nd level new"
//                 }
//               ]
//             }
//           ]
//         }
//       ]
//     }
//   ]
// }

Running Tests

npm install
npm test

Credits

Special thanks to the folks behind pyTree, from which this code is largely derived.