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

graphbox

v1.3.0

Published

Graph Sandbox + Graph Toolbox: Abstract and experimental graph algorithms for academic research

Readme

GraphBox

This file provides guidance to Claude Code (claude.ai/code) when working with this repository.

GraphBox = Graph Sandbox + Graph Toolbox

Abstract and experimental graph algorithms for academic research. The name reflects its dual purpose:

  • Sandbox — A space for experimenting with graph algorithms, data structures, and traversal strategies
  • Toolbox — A collection of reusable, well-tested graph utilities for production use

GraphBox provides a toolkit for graph manipulation, analysis, and generation, specifically designed for academic research in graph theory, network science, and citation analysis.

Overview

GraphBox consolidates three previously separate BibGraph packages into a single, focused package:

  • graph-core: Core graph interfaces and adapters
  • graph-expansion: Graph expansion, traversal algorithms, and neighborhood exploration
  • graph-gen: Graph specification, generation, and validation system

Installation

pnpm install graphbox

Commands

# Development
pnpm install              # Install dependencies
pnpm typecheck            # TypeScript type checking
pnpm lint                 # ESLint with auto-fix
pnpm test                 # Run unit tests with coverage
pnpm build                # Build library + CLI

# Experiments (high memory required)
NODE_OPTIONS="--max-old-space-size=8192" pnpm test:metrics    # Run experiments, generate metrics
pnpm gen:latex-tables                                     # Generate LaTeX tables from metrics
pnpm update:thesis-tables                                  # Full: experiments + LaTeX table generation

# Standalone experiment orchestrator
npx tsx src/experiments/run-experiments.ts                 # Run all experiments
npx tsx src/experiments/run-experiments.ts --output path   # Custom output path

# CLI
npx graphbox help       # Show available commands
npx graphbox version    # Show version
npx graphbox generate   # Generate graphs from specifications
npx graphbox analyze    # Analyze graph properties
npx graphbox validate   # Validate graphs against constraints

Key Features

Graph Adapters

GraphAdapter provides a bridge between different graph implementations, allowing you to use generic algorithms with your specific graph data structures.

import { GraphAdapter } from 'graphbox';

const adapter = new GraphAdapter(graph);

Graph Traversal

Multiple traversal algorithms for exploring graph neighborhoods:

  • BFS - Breadth-first search
  • DFS - Depth-first search
  • Bidirectional BFS - Optimized bidirectional search
  • Degree-Prioritized - Expansion based on node degree
  • Priority Queue - Custom priority-based expansion
import { bfs, dfs, extractEgoNetwork } from 'graphbox';

const bfsResult = bfs(adapter, 'startNodeId');
const dfsResult = dfs(adapter, 'startNodeId');

Graph Extraction

Extract ego networks and multi-source neighborhoods:

const egoNetwork = extractEgoNetwork(adapter, {
  radius: 2,
  seedNodes: ['nodeId'],
});

Graph Generation

Type-safe graph generation with mathematical constraint validation:

import { generateGraph, validateGraph } from 'graphbox';

const spec = {
  type: 'complete',
  nodeCount: 100,
  edgeDensity: 0.1,
  constraints: {
    minDegree: 2,
    maxDegree: 10,
    connected: true
  }
};

const graph = generateGraph(spec);
const valid = validateGraph(graph, spec.constraints);

Graph Validation

Mathematical constraint validation for graph properties:

import { validateGraph, checkConstraints } from 'graphbox';

const isValid = validateGraph(graph, constraints);

Architecture

Experiment Framework

The evaluation harness provides reusable, repeatable, reproducible experiments:

  1. src/experiments/run-experiments.ts - Orchestrator that runs all experiments

  2. src/experiments/metrics/ - Typed metrics collection system

    • types.ts - All metric type interfaces (must conform for table generation)
    • collector.ts - MetricsCollector class for recording metrics
    • storage.ts - File I/O for test-metrics.json
  3. src/experiments/experiments/ - Standalone experiment scripts

    • bidirectional-bfs.ts - Degree-Prioritised vs baselines
    • seeded-expansion.ts - N=1 ego-network, N=2 bidirectional, N>=3 multi-seed
    • path-ranking.ts - Path Salience Ranking with MI-based ranking
  4. scripts/export-csv.ts - Exports metrics as per-category CSV files for pgfplotstable

Pipeline: Experiments → MetricsCollector → test-metrics.json → CSV files → LaTeX pgfplotstable

Three Algorithms Evaluated

  1. Seeded Node Expansion

    • N=1: Ego-network extraction
    • N=2: Bidirectional path finding
    • N>=3: Multi-seed expansion
  2. Bidirectional BFS (Degree-Prioritised Expansion)

    • Degree-based prioritisation vs standard BFS, frontier-balanced, random priority
    • Hub explosion mitigation
  3. Salient Path Selection

    • Mutual Information (MI) based path ranking
    • Statistical significance testing (Mann-Whitney U, Cohen's d)

Graph Abstraction

  • ReadableGraph<N, E> - Minimal interface for graph traversal
  • GraphAdapter - Adapter pattern for different graph implementations
  • GraphExpander - Interface for dynamic graph expansion (used by algorithms)
  • BenchmarkGraphExpander - Wraps loaded benchmark graphs for algorithm compatibility

Path Aliases

TypeScript paths configured in tsconfig.json:

@graph/algorithms/*    → src/algorithms/*
@graph/interfaces/*    → src/interfaces/*
@graph/evaluation/*    → src/experiments/evaluation/*
@graph/experiments/*   → src/experiments/*

Test Organization

  • .exp.integration.test.ts - Experiment tests (high memory, use --max-old-space-size=8192)
  • Unit tests - Co-located with algorithms
  • Benchmarks - src/experiments/evaluation/__tests__/validation/*/benchmarks/
  • Fixtures - src/experiments/evaluation/__tests__/validation/*/fixtures/

Build System

Dual build targets via Vite:

  • Library: ES modules, CJS, UMD formats (browser-compatible)
  • CLI: ESM-only for Node.js command-line interface

API Reference

Core Classes

  • GraphAdapter - Adapter pattern for graph abstraction
  • GraphExpander - Interface for dynamic graph expansion
  • PriorityQueue - Priority queue for degree-based expansion

Traversal Algorithms

  • bfs(adapter, startNodeId, options?) - Breadth-first search
  • dfs(adapter, startNodeId, options?) - Depth-first search
  • BidirectionalBFS - Bidirectional BFS search

Extraction Methods

  • extractEgoNetwork(adapter, options) - Extract ego-centered subgraph
  • extractMultiSourceEgoNetwork(adapter, options) - Multi-source extraction

Generation Functions

  • generateGraph(spec) - Generate graph from specification
  • validateGraph(graph, constraints) - Validate graph against constraints

Key Constraints

  • Never use any - Use unknown with type guards
  • Serial test execution - Parallel causes OOM on large graphs
  • Memory limits - Use NODE_OPTIONS="--max-old-space-size=8192" for experiments
  • Metric types - All metrics must conform to types in src/experiments/metrics/types.ts

LaTeX Table Generation

The experiment pipeline can generate LaTeX tables (.tex files) consumable by pgfplotstable.

Table-to-metric mapping: | Table | Metric Category | |-------|-----------------| | 06-runtime-performance.tex | runtime-performance | | 06-path-lengths.tex | path-lengths | | 06-scalability.tex | scalability | | 06-n-seed-hub-traversal.tex | n-seed-hub-traversal | | 06-statistical-significance.tex | statistical-significance | | 06-cross-dataset.tex | cross-dataset | | 06-method-ranking.tex | method-ranking | | 06-structural-representativeness.tex | structural-representativeness | | 06-n-seed-generalisation.tex | n-seed-generalization | | 06-n-seed-comparison.tex | n-seed-comparison | | 06-n-seed-path-diversity.tex | n-seed-path-diversity | | 06-structural-representativeness-metrics.tex | structural-representativeness-metrics | | 06-mi-ranking-quality.tex | mi-ranking-quality |

Contributing

This package is part of academic research work. Contributions are welcome, please open an issue first.

License

MIT

Author

Joe Mearman

Related Projects

  • BibGraph - React SPA for OpenAlex literature discovery