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

implication-chain-set

v0.0.1

Published

Build and query transitive implication relationships from chains, trees, and graphs.

Readme

implication-chain-set

Build and query transitive implication relationships from ordered chains, trees, and directed graphs.

In this package, a more specific item implies a more general item. For the chain animal -> mammal -> cat, cat implies both mammal and animal.

Install

pnpm add implication-chain-set

implication-chain-set is ESM-only and supports Node.js 20 or newer.

Quick start

import { ImplicationChainSet } from "implication-chain-set";

const implications = new ImplicationChainSet()
  .addChain(["animal", "mammal", "human"])
  .addChain(["animal", "feline", "cat"])
  .addDescendantsTo("living thing", ["animal"]);

implications.implies("cat", "animal"); // true
implications.getNearestAncestors("cat"); // Set { "feline" }
implications.getFarthestAncestors("cat"); // Set { "living thing" }
implications.getUpPaths("cat", "living thing");
// [["cat", "feline", "animal", "living thing"]]

Add relationships

  • addChain(chain) and addChains(chains) accept general-to-specific ordered chains and derive their transitive implication closure.
  • addTree(tree) and addTrees(trees) accept nested { name, children } nodes. Parent-child relationships are recorded as explicit edges.
  • addGraph(graph) and addGraphs(graphs) accept { nodes, edges }, where an edge { from, to } means to implies from.
  • addDescendantsTo(ancestor, descendants) and addAncestorsTo(descendant, ancestors) add explicit edges directly.

Chains provide ordering evidence but do not create explicit edges. Use trees, graphs, or the explicit ancestor/descendant methods when explicit-path queries must preserve the input edges.

Query relationships

  • implies(from, to) includes reflexive implication: every item implies itself.
  • getImpliedItems(from) returns all ancestors implied by from.
  • getItemsImplying(to) returns all descendants that imply to.
  • getNearestAncestors / getNearestDescendants return the transitive reduction inferred from all known relationships.
  • getFarthestAncestors / getFarthestDescendants return the outermost known items.
  • Methods prefixed with getExplicit only inspect explicitly added edges.

Returned sets and items are detached snapshots, so modifying them never changes the ImplicationChainSet.

Query paths

getUpPaths, getDownPaths, and getAllPaths return the longest matching simple paths. Their getExplicit... counterparts use only explicit edges.

Every path method accepts an optional third argument:

implications.getUpPaths("cat", "animal", {
  maxDepth: 4, // maximum edges traversed
  maxPaths: 10, // maximum matches collected
});

Both limits must be non-negative integers. A maxPaths value of 0 returns no paths.

Diagnostics

getDiagnostics() reports implication cycles. Each cycle contains one sorted strongly connected component:

const cyclic = new ImplicationChainSet()
  .addDescendantsTo("A", ["B"])
  .addDescendantsTo("B", ["C"])
  .addDescendantsTo("C", ["A"]);

cyclic.getDiagnostics();
// { cycles: [{ items: ["A", "B", "C"] }] }

Development

pnpm install
pnpm run verify

verify checks source and test types, runs the test suite, builds the package, and installs the generated tarball into an isolated consumer project.

License

MIT