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

dijkstra-find-path

v2.0.0

Published

TypeScript implementation of Dijkstra's single-source shortest-paths algorithm, including performance optimizations based on the `heapq` Python library.

Readme

dijkstra-find-path

TypeScript implementation of Dijkstra's single-source shortest-paths algorithm, with performance optimizations based on the heapq Python library.

The code was originally written by Wyatt Baldwin and turned into a Node.js module by Thomas Cort. Ported to TypeScript by Samuel Plumppu.

Features

  • Works with any JS runtime: Pure JS implementation without any platform-specific APIs.
  • Tiny code footprint: Only 0.54 kB minified + gzipped, making this suitable to include in web apps where the bundle size is important.
  • Improved performance: Using a min-heap which especially improves the performance of larger graphs. See benchmark below.
  • TypeScript definitions included.
  • Easy to upgrade from [email protected] thanks to the backwards-compatible API and implementation. Just rename one function and you're good to go. See the CHANGELOG for a detailed upgrade guide.
  • Comprehensive test suite, including the original tests from dijkstrajs, extended with new tests to verify the performance improvements.

Get started

pnpm install dijkstra-find-path
import { findPath } from 'dijkstra-find-path'

const graph = {
  a: { b: 10, c: 100, d: 1 },
  b: { c: 10 },
  d: { b: 1, e: 1 },
  e: { f: 1 },
  f: { c: 1 },
  g: { b: 1 },
}

// Find the shortest path from 'a' to 'c'
let path = findPath(graph, 'a', 'c')
// ['a', 'd', 'e', 'f', 'c']

// Find the shortest path from 'd' to 'b'
path = findPath(graph, 'd', 'b')
// ['d', 'b']

More examples

See the tests at the bottom of src/dijkstra.ts to find more example code.

Benchmarks

Run benchmarks with pnpm bench.

Comparing [email protected] (JS) with optimized version [email protected] (TS):

┌─────────┬─────────────────────────────────┬────────────────────┬─────────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name                       │ Latency avg (ns)   │ Latency med (ns)    │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼─────────────────────────────────┼────────────────────┼─────────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0       │ `[email protected] (JS)`         │ `13664463 ± 1.10%` │ `13227474 ± 189456` │ `73 ± 0.90%`           │ `76 ± 1`               │ 147     │
│ 1       │ `[email protected] (TS)` │ `12701920 ± 1.77%` │ `12041805 ± 127453` │ `79 ± 1.36%`           │ `83 ± 1`               │ 158     │
└─────────┴─────────────────────────────────┴────────────────────┴─────────────────────┴────────────────────────┴────────────────────────┴─────────┘

Based on the sample graph in the benchmark, this library runs 9% faster compared to the unoptimized version. This might not seem like much for a small graph, but for larger amounts of data, this adds up.

This is not a perfect benchmark, and I haven't included all large graphs I tested to keep the repo clean. However, this is a starting point to make sure this library performs well, and help catch performance regressions in the future. You're welcome to contribute to the project you find ways to further improve the library and benchmarks!

License

MIT

This library includes derived code from the heapq library, ported from Python 3.14.3 Original license for heapq: PSF-2.0