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

@typesugar/graph

v0.1.0

Published

Compile-time graph algorithms and state machine verification — Boost.Graph for TypeScript

Downloads

57

Readme

@typesugar/graph

Compile-time graph algorithms and state machine verification for TypeScript, inspired by Boost.Graph.

Define graphs and state machines via a concise DSL or programmatic API, then run classic algorithms (topological sort, shortest path, SCC, cycle detection) and verify state machine properties (reachability, dead ends, nondeterminism) — all with immutable data structures.

Quick Start

import { digraph, topoSort, shortestPath } from "@typesugar/graph";

const g = digraph`
  task-a -> task-b, task-c
  task-b -> task-d
  task-c -> task-d
`;

const sorted = topoSort(g);
// { ok: true, order: ["task-a", "task-b", "task-c", "task-d"] }

const path = shortestPath(g, "task-a", "task-d");
// ["task-a", "task-b", "task-d"]

State Machines

Define, verify, and run state machines:

import { stateMachine, verify, createInstance } from "@typesugar/graph";

const order = stateMachine`
  @initial Created
  @terminal Delivered, Cancelled
  Created --submit--> Pending
  Pending --approve--> Approved
  Pending --reject--> Rejected
  Pending --cancel--> Cancelled
  Approved --ship--> Shipped
  Shipped --deliver--> Delivered
`;

const result = verify(order);
// {
//   valid: false,
//   unreachableStates: [],
//   deadEndStates: ["Rejected"],  // not declared terminal
//   nondeterministic: [],
//   cycles: []
// }

const inst = order.create();
const shipped = inst
  .transition("submit")
  .transition("approve")
  .transition("ship");
shipped.current; // "Shipped"
shipped.availableEvents(); // ["deliver"]

Graph Construction

DSL

import { digraph, graph } from "@typesugar/graph";

// Directed graph
const dg = digraph`
  a -> b, c
  b -> d [weight]
`;

// Undirected graph
const ug = graph`
  a -> b
  b -> c
`;

Programmatic API

import { createDigraph, createGraph, addNode, addEdge } from "@typesugar/graph";

const g = createDigraph(["a", "b", "c"], [
  ["a", "b"],
  ["b", "c"],
]);

// Immutable — returns new graphs
const g2 = addNode(g, "d");
const g3 = addEdge(g2, "c", "d", "next", 5);

Algorithms

| Algorithm | Function | Complexity | | --- | --- | --- | | Topological sort | topoSort(g) | O(V + E) | | Cycle detection | detectCycles(g), hasCycles(g) | O(V + E) | | BFS / DFS | bfs(g, start), dfs(g, start) | O(V + E) | | Reachability | reachable(g, start), hasPath(g, a, b) | O(V + E) | | Shortest path (unweighted) | shortestPath(g, a, b) | O(V + E) | | Shortest path (weighted) | dijkstra(g, a, b) | O(V^2) | | Strongly connected components | stronglyConnectedComponents(g) | O(V + E) | | DAG check | isDAG(g) | O(V + E) | | Transitive closure | transitiveClosure(g) | O(V * (V + E)) | | Reverse graph | reverseGraph(g) | O(V + E) |

State Machine Verification

verify(sm) checks for common structural issues:

  • Unreachable states — states not reachable from the initial state
  • Dead-end states — states with no outgoing transitions that aren't declared terminal
  • Nondeterminism — same state + same event leading to different targets
  • Cycles — cyclic paths through the state graph

State Machine DSL

@initial StateName
@terminal State1, State2
FromState --event--> ToState

Lines starting with # are comments. Blank lines are ignored.

Future

  • Compile-time verification — run verify() via comptime() during compilation
  • Effect layer integration — state machine as an Effect service layer
  • Visualization — DOT/Mermaid output for graph rendering