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

v0.1.1

Published

Full OSM toolkit for JavaScript and TypeScript

Readme

osmix

osmix is the high-level entrypoint for the Osmix toolkit. It layers ingestion, streaming, and worker orchestration utilities on top of the low-level @osmix/core index so you can load .osm.pbf files, convert GeoJSON, and request raster/vector tiles with a single import.

Installation

bun install osmix

Usage

Load a PBF and inspect it

import { fromPbf, fromGeoJSON, toPbfBuffer } from "osmix"

const monacoPbf = await Bun.file("./monaco.pbf").arrayBuffer()
const osm = await fromPbf(monacoPbf)

console.log(osm.nodes.size, osm.ways.size, osm.relations.size)

const geojsonFile = await fetch("/fixtures/buildings.geojson").then((r) => r.arrayBuffer())
const geoOsm = await fromGeoJSON(geojsonFile)
const pbfBytes = await toPbfBuffer(geoOsm)

Work off the main thread with OsmixRemote

import { createRemote } from "osmix"

const remote = await createRemote()
const monacoOsmInfo = await remote.fromPbf(monacoPbf)
const patchOsmInfo = await remote.fromPbf(Bun.file("patch.osm.pbf").stream(), {
	id: "patch",
})
await remote.merge(monacoOsmInfo, patchOsmInfo)
const rasterTile = await remote.getRasterTile(monacoOsmInfo, [10561, 22891, 16])

How?

OsmixRemote automatically transfers typed arrays across workers (using SharedArrayBuffer when available) and exposes the same helpers exposed in the main import: fromPbf, fromGeoJSON, getVectorTile, getRasterTile, search, merge, generateChangeset, etc. Use collectTransferables + transfer when you need to post Osmix payloads through your own worker setup.

Routing with workers

OsmixRemote provides off-thread routing via @osmix/router. The routing graph builds lazily on first use, so there's no upfront cost until you actually route.

import { createRemote } from "osmix"

const remote = await createRemote()
const osmInfo = await remote.fromPbf(monacoPbf)

// Find nearest routable nodes to coordinates
const from = await remote.findNearestRoutableNode(osmInfo.id, [7.42, 43.73], 0.5)
const to = await remote.findNearestRoutableNode(osmInfo.id, [7.43, 43.74], 0.5)

if (from && to) {
	// Calculate route with statistics and path info
	const result = await remote.route(osmInfo.id, from.nodeIndex, to.nodeIndex, {
		includeStats: true,
		includePathInfo: true,
	})

	if (result) {
		console.log(result.coordinates) // Route geometry
		console.log(result.distance) // Distance in meters
		console.log(result.time) // Time in seconds
		console.log(result.segments) // Per-way breakdown
	}
}

The routing graph is automatically shared across all workers when using SharedArrayBuffer, so any worker can handle routing requests.

Extract, stream, and write back to PBF

import { fromPbf, createExtract, toPbfStream } from "osmix"

const osm = await fromPbf(Bun.file('./monaco.pbf').stream())
const downtown = createExtract(osm, [-122.35, 47.60, -122.32, 47.62])
await toPbfStream(downtown).pipeTo(fileWritableStream)

createExtract can either clip ways/members to the bbox (strategy: "simple") or include complete ways/relations. toPbfStream and toPbfBuffer reuse the streaming builders from @osmix/json/@osmix/pbf, so outputs stay spec-compliant without staging everything in memory.

API

Loading

  • fromPbf(data, options?) - Load OSM data from PBF (buffer, stream, or File).
  • fromGeoJSON(data, options?) - Load OSM data from GeoJSON.
  • readOsmPbfHeader(data) - Read only the PBF header without loading entities.

Export

  • toPbfStream(osm) - Stream Osm to PBF bytes (memory-efficient).
  • toPbfBuffer(osm) - Convert Osm to a single PBF buffer.

Extraction

  • createExtract(osm, bbox, strategy?) - Create geographic extract.
    • "simple" - Strict spatial cut.
    • "complete_ways" - Include complete way geometry.
    • "smart" - Complete ways + resolved multipolygons.

Tiles

  • drawToRasterTile(osm, tile, tileSize?) - Render Osm to raster tile.

Workers (OsmixRemote)

  • createRemote(options?) - Create worker pool manager.
  • remote.fromPbf(data, options?) - Load in worker.
  • remote.fromGeoJSON(data, options?) - Load in worker.
  • remote.getVectorTile(osmId, tile) - Generate MVT in worker.
  • remote.getRasterTile(osmId, tile, tileSize?) - Generate raster in worker.
  • remote.merge(baseId, patchId, options?) - Merge datasets in worker.
  • remote.search(osmId, key, val?) - Search by tag.
  • remote.toPbf(osmId, stream) - Export to PBF.

Routing

  • remote.buildRoutingGraph(osmId, filter?, speeds?) - Explicitly build routing graph (optional, builds lazily on first use).
  • remote.hasRoutingGraph(osmId) - Check if routing graph exists.
  • remote.findNearestRoutableNode(osmId, point, maxKm) - Snap coordinate to nearest routable node.
  • remote.route(osmId, fromIndex, toIndex, options?) - Calculate route between nodes.
    • options.includeStats - Include distance and time in result.
    • options.includePathInfo - Include segments and turnPoints in result.

Utilities

  • collectTransferables(value) - Find transferable buffers in nested objects.
  • transfer(data) - Wrap data for zero-copy worker transfer.

Related Packages

Environment and limitations

  • Requires runtimes that expose Web Streams plus modern typed array + compression APIs (Node 20+, Bun, current browsers). OsmixRemote also requires Worker support and, for multi-worker concurrency, SharedArrayBuffer.
  • fromPbf expects dense-node blocks; sparse node encodings are not yet supported.
  • Raster helpers rely on OffscreenCanvas + ImageData.

Development

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

Run bun run check from the repo root before publishing to keep formatting, lint, and types consistent.