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

hierutil

v3.2.3

Published

hierarchy utility methods

Downloads

1,338

Readme

hierUtil

A TypeScript library providing utilities for hierarchical data manipulation, tree traversal, and data validation. Designed for handling complex tree structures and performing operations such as searching, filtering, and transforming nodes.

Installation

npm install hierutil

Usage

Import the desired functions from the library:

import { treeDFSTravers, getAllNodes, searchTreeNodes, checkCondition } from 'hierutil';

Key Functions

Tree Traversal and Manipulation

  • treeDFSTravers(root, func, afterFunc): Performs a depth-first search (DFS) traversal on a tree, applying func to each node and optionally afterFunc after processing children.
  • getAllNodes(root, cf='children'): Retrieves all nodes in the tree as an array.
  • getLeafNodes(root, cf='children'): Returns an array of leaf nodes (nodes without children).
  • getSubTreeNodes(root, checkFunc, cf='children'): Collects all nodes in subtrees where checkFunc returns true.
  • getSubTreeRoots(root, checkFunc, cf='children'): Returns the root nodes of subtrees where checkFunc returns true.
  • getTopTree(root, top): Constructs a new tree containing the top top nodes, preserving parent-child relationships.
  • getPartialTreeNodes(root, list, keyField='RESULT_NODE'): Extracts a partial tree containing nodes from list and their ancestors.
  • getExcludeTree({tree, excluded, keyField='RESULT_NODE'}): Returns a tree excluding nodes specified in excluded.
  • markNodeNum(root, cf='children'): Annotates each node with a childCount property representing the number of descendants.
  • cleanTreeNodes(result): Removes specified properties (parent, children, group, groupId) from nodes.

Search Functions

  • searchTreeNodes(root, field, value, cf='children'): Searches for nodes where field matches value. Supports single or multiple value searches.
  • findSubTreeNodes(root, checkFunc, cf='children'): Finds the first subtree where checkFunc returns true.
  • treeSearchByHierarchy(root, branches, target, options): Searches for a target node within branches specified by branches.
  • findFirstLeaf(tree, cf='children'): Returns the first leaf node in a tree.
  • findLastLeaf(tree, cf='children'): Returns the last leaf node in a tree.

Data Validation

  • checkCondition(sheetData, snapShot, auto, condList): Validates data rows against conditions, supporting multiple versions and dimensions. Returns a status and any exceptions found.
  • compareOper(oper, val1, val2): Compares two values using operators like =, >, <, >=, <=, <>.
  • calcOper(oper, val1, val2): Performs calculations (+, -, *, /, +%, -%) on two values.

Utility Functions

  • removeBlankBranch(list): Removes hidden nodes and consolidates groups in a list of nodes.
  • removeDupColFields(colFields, axis0List): Removes duplicate column fields based on IDs.
  • printMsg(): Logs a message indicating the library's usage.

Example

// Example tree structure
const tree = {
  id: 1,
  children: [
    { id: 2, children: [] },
    { id: 3, children: [{ id: 4, children: [] }] }
  ]
};

// Get all leaf nodes
const leaves = getLeafNodes(tree);
console.log(leaves); // [{ id: 2, children: [] }, { id: 4, children: [] }]

// Search for a node by field value
const found = searchTreeNodes(tree, 'id', 3);
console.log(found); // { id: 3, children: [{ id: 4, children: [] }] }

// Validate data
const sheetData = { rowData: [{ data: 10 }], dateFieldList: ['data'] };
const snapShot = { dimFields: [], onColDims: [{ code: 'data' }], versionCompare: {} };
const auto = { MISC: JSON.stringify({ condJoinType: 'AND' }) };
const condList = [{ condition: 0, compType: 'valueBase', compOper: '>', compInput: 5 }];
const result = checkCondition(sheetData, snapShot, auto, condList);
console.log(result); // { status: false, exceptions: [...] }

Notes

  • The library assumes a default children field name of 'children', but this can be customized via the cf parameter in most functions.
  • Functions like checkCondition are designed for specific data validation scenarios, particularly with multi-version and multi-dimensional data.
  • Ensure that input data structures are properly formatted to avoid unexpected behavior.

License

Commercial mdxpro.ai