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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@orioro/tree-model

v1.2.0

Published

``` npm install @orioro/tree-model yarn add @orioro/tree-model ```

Downloads

4

Readme

treeModel

npm install @orioro/tree-model
yarn add @orioro/tree-model

API Docs

stateCache()

Creates a cache getter that memoizes the last state and returns corresponding cache object. If the state object changes, the previous cache object is abandoned and a new cache object is returned.

The cache object itself is a JS Map

  • Returns: getStateCache {Function}
memoizeStateQuery(queryFn, keyResolver)

Memoizes a function that takes as first argument the state object. If the state changes (by identity/reference comparison), cache is reset.

Calls to the memoized function attempt to locate a result in the cache object.

  • queryFn {Function}
  • keyResolver {Function}
tree.nodeIdArray(nodesById)
tree.nodeArray(nodesById)
tree.nodeTree(nodesById, nodeId)
tree.isRoot(nodesById, nodeId)

Returns whether the given node is the root node (parentId === null)

  • nodesById {TreeState}
  • nodeId {[NodeId](#nodeid)}
  • Returns: {Boolean}
tree.rootNodeId(nodesById)
tree.ancestorIds(nodesById, nodeId)

Retrieves the list of node ancestors by walking up the tree using node.parentId

tree.nodePath(nodesById, nodeId)

Returns the full path up to the node. A node path is an array of nodeIds in sequence.

tree.isAncestorOf(nodesById, candidateAncestorId, candidateDescendantId)
  • nodesById {TreeState}
  • candidateAncestorId {[NodeId](#nodeid)}
  • candidateDescendantId {[NodeId](#nodeid)}
  • Returns: {Boolean}
tree.isDescendantOf(nodesById, candidateDescendantId, candidateAncestorId)
  • nodesById {TreeState}
  • candidateDescendantId {[NodeId](#nodeid)}
  • candidateAncestorId {[NodeId](#nodeid)}
  • Returns: {Boolean}
tree.childIds(nodesById, nodeId)
tree.isChildOf(nodesById, nodeId, candidateParentNodeId)
  • nodesById {TreeState}
  • nodeId {[NodeId](#nodeid)}
  • candidateParentNodeId {[NodeId](#nodeid)}
  • Returns: {Boolean}
tree.isChildOf(nodesById, nodeId, candidateChildNodeId)
  • nodesById {TreeState}
  • nodeId {[NodeId](#nodeid)}
  • candidateChildNodeId {[NodeId](#nodeid)}
  • Returns: {Boolean}
tree.siblingIds(nodesById, nodeId)
tree.isSiblingOf(nodesById, nodeId, otherNodeId)
  • nodesById {TreeState}
  • nodeId {[NodeId](#nodeid)}
  • otherNodeId {[NodeId](#nodeid)}
  • Returns: {Boolean}
tree.commonPath(nodesById, nodeIds)
tree.commonAncestorPath(nodesById, nodeIds)
tree.commonAncestorId(nodesById, nodeIds)
  • nodesById {TreeState}
  • nodeIds {[NodeId](#nodeid)[]}
  • Returns: {[NodeId](#nodeid) | null}
NodeId

String

NodePath

A sequence of nodeIds that lead to the last node

Node
{
  id: NodeId
  parentId: NodeId | null
  [key: string]: any
}
TreeState

Index of all nodes that compose the tree indexed by id: { [key: string]: [Node](#node) }

NodeTree

Tree representation of the node [Node, NodeTree[] | null]

fromNodeArray(nodeArray)

Generates a tree state (nodes indexed by id) from an array of node objects.

commonPath(paths)

Given a set of NodePaths, return the longest common path

  • paths {[NodePath](#nodepath)[]}
  • Returns: commonPath {[NodePath](#nodepath)}