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

@osmix/router

v0.0.4

Published

A routing engine for OSM data built on top of @osmix/core

Readme

@osmix/router

@osmix/router builds a routable street network from OSM data and provides routing functionality to find paths between coordinates.

Highlights

  • Builds a directed graph from OSM ways and nodes
  • Configurable highway type filtering
  • Multiple routing algorithms (Dijkstra, A*, bidirectional search)
  • Support for both distance and time-based routing
  • Returns detailed route information including coordinates, way IDs, and node IDs
  • Serializable graph format for Web Worker support

Installation

bun install @osmix/router

Usage

import { RoutingGraph, Router, findNearestNodeOnGraph } from "@osmix/router"
import { Osm } from "@osmix/core"

const osm = new Osm()
// ... load OSM data into osm ...

// Build routing graph
const graph = new RoutingGraph(osm)

// Snap coordinates to nearest routable nodes
const from = findNearestNodeOnGraph(osm, graph, [-73.989, 40.733], 0.5)
const to = findNearestNodeOnGraph(osm, graph, [-73.988, 40.734], 0.5)

if (from && to) {
	const router = new Router(osm, graph)
	const path = router.route(from.nodeIndex, to.nodeIndex)

	if (path) {
		const result = router.buildResult(path)
		console.log(result.coordinates) // Array of [lon, lat] coordinates
		console.log(result.wayIndexes) // Array of way indexes used
		console.log(result.nodeIndexes) // Array of node indexes for turns
	}
}

API

RoutingGraph

Build and manage a routing graph from OSM data. The graph uses a CSR (Compressed Sparse Row) format for efficient memory usage and cache locality.

import { RoutingGraph, defaultHighwayFilter } from "@osmix/router"

// Build from OSM data
const graph = new RoutingGraph(osm, defaultHighwayFilter)

// Properties
graph.size // Number of routable nodes
graph.edges // Total edge count
graph.isRouteable(nodeIndex) // Check if node is routable
graph.isIntersection(nodeIndex) // Check if node is an intersection
graph.getEdges(nodeIndex) // Get outgoing edges from node

findNearestRoutableNode(osm, point, maxKm)

Snap a geographic coordinate to the nearest routable node.

const nearest = graph.findNearestRoutableNode(osm, [-73.989, 40.733], 0.5)
if (nearest) {
	console.log(nearest.nodeIndex) // Internal node index
	console.log(nearest.coordinates) // Snapped [lon, lat]
	console.log(nearest.distance) // Distance from input point (meters)
}

Constructor parameters:

  • osm - The @osmix/core dataset.
  • filter - Optional function (tags?) => boolean to select routable ways. Default: common vehicle highways.
  • defaultSpeeds - Optional speed limits (km/h) by highway type.

Serialization (Web Worker support)

RoutingGraph can be serialized and transferred between Web Workers:

// Build graph and get transferables
const graph = new RoutingGraph(osm)
const transferables = graph.transferables()

// Transfer to worker (zero-copy with SharedArrayBuffer)
worker.postMessage(transferables)

// Reconstruct in worker
const reconstructed = new RoutingGraph(transferables)

The transferables() method returns an object containing:

  • nodeCount, edgeCount - Graph dimensions
  • edgeOffsets, edgeTargets, edgeWayIndexes - CSR structure
  • edgeDistances, edgeTimes - Edge weights
  • routableBits, intersectionBits - Node flags

Router

High-level routing interface.

const router = new Router(osm, graph, { algorithm: "astar", metric: "time" })

Methods:

  • route(fromNodeIndex, toNodeIndex, options?) - Find path between nodes. Returns PathSegment[] or null.
  • buildResult(path) - Convert path to RouteResult with coordinates and metadata.

Options:

  • algorithm - "dijkstra" | "astar" | "bidirectional" (default: "astar")
  • metric - "distance" | "time" (default: "distance")

Algorithms

| Algorithm | Optimal? | Speed | Best For | | --------------- | -------- | ------- | ------------------------------------- | | dijkstra | Yes | Slower | When you need guaranteed shortest path | | astar | Yes | Fast | Point-to-point queries (default) | | bidirectional | No | Fastest | Quick connectivity checks |

Related Packages

  • @osmix/core - In-memory OSM index with spatial queries.
  • @osmix/shared - Haversine distance and coordinate utilities.
  • osmix - High-level API with worker support for routing.

Development

  • bun run test packages/router
  • bun run lint packages/router
  • bun run typecheck packages/router

Run bun run check at the repo root before publishing to ensure formatting, lint, and type coverage.