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

@osm-editor-kit/osm-way-chain

v1.0.1

Published

Traverse and orient connected OSM highway ways for multi-segment editing sessions.

Downloads

929

Readme

@osm-editor-kit/osm-way-chain

Walk connected OSM ways from a center way and orient them into one chain, for editors that change several segments of a street at once.

[!NOTE] Claude Opus 5.5 wrote and reviewed the code of this package. @tordans specified what it should do and tested and verified its user-facing behavior.

Install

npm install @osm-editor-kit/osm-way-chain

It depends on @osm-editor-kit/osm-data, which npm installs for you.

What it does

  • Walks connected ways left and right from a center way
  • Ranks neighbor candidates (same kind of road, name, ref)
  • Reports junctions where more than one neighbor is equally good, so the user can choose
  • Flips geometry and directional tags when a way is digitized the "wrong" way (mirrorTags)
  • Compiles app-owned way-selection policies to Overpass queries and matches them against in-memory tags
  • Reads from an in-memory ParsedOsmData session (createSessionGraphAdapter) or any data source that implements OsmDataAdapter

Usage

import type { ParsedOsmData } from '@osm-editor-kit/osm-data'
import {
  buildChain,
  buildWaysOverpassQuery,
  createSessionGraphAdapter,
  matchesOsmWaySelectionSegment,
  tag,
  type OsmWaySelectionPolicy,
} from '@osm-editor-kit/osm-way-chain'

// App-owned contract: which ways to download and chain. The package has no defaults.
const wayPolicy: OsmWaySelectionPolicy = {
  include: [
    { all: [tag.oneOf('highway', ['residential', 'cycleway', 'path', 'footway', 'steps'])] },
  ],
  globalAll: [tag.neq('access', 'private'), tag.neq('access', 'no')],
}

const graph: ParsedOsmData = /* loaded viewport data */
const adapter = createSessionGraphAdapter(graph)

const { chain, pendingJunctions } = await buildChain(adapter, {
  centerWayId: 123456,
  maxPerSide: 5,
  candidateFilter: (candidate) => matchesOsmWaySelectionSegment(candidate, wayPolicy),
})

// Overpass query that downloads the same ways for a bbox (south,west,north,east):
const query = buildWaysOverpassQuery(wayPolicy, '52.5,13.4,52.51,13.41')

buildChain returns the ordered chain.segments, the index of the center way in chain.centerIndex, and pendingJunctions for places where it could not pick a neighbor.

Junctions

When a junction has several equally good neighbors, buildChain stops there and lists them in pendingJunctions. Let the user pick one, then continue with extendChainAtJunction(adapter, chain, choice, selectedWayId, { maxPerSide, candidateFilter }). Use recenterChain(chain, wayId) to move the center to another way in the chain without reloading; it returns the chain unchanged when the way is not part of it.

Way-selection policies

A policy is a list of include clauses (OR), each a list of tag predicates (AND), plus optional globalAll predicates added to every clause. Build predicates with tag.eq, tag.neq, tag.oneOf, tag.noneOf, tag.regex, tag.nregex, tag.present and tag.absent. compileOverpassWaySelectors returns one Overpass filter per clause, matchesOsmWaySelection tests in-memory tags. A missing tag matches neq, noneOf, nregex and absent, as in Overpass.

tag.regex and tag.nregex patterns run as JavaScript RegExp in memory but go to Overpass unchanged, where they are POSIX extended regular expressions. Use only syntax both understand: anchors, groups, |, [...], *, +, ?, {n,m}. \d, (?:...), lookarounds and lazy quantifiers behave differently or fail in Overpass.

Helpers

  • mirrorTags(tags) returns the tags as if the way were digitized the other way round (left/right, forward/backward, oneway, *:lanes, placement). normalizeTagsForDirection(tags, reversed) applies it only when reversed; swapLeftRightKey(key) swaps one key.
  • orientNeighbor(neighbor, sharedNodeId, from) flips a neighbor so it runs in the direction of from.
  • getSharedNodeBetween(a, b), getEndpointNodeId(segment, direction) and getOtherEndpointNodeId(segment, nodeId) read way endpoints.
  • osmWayToSegment(way, nodeCoords) turns an OsmWay from @osm-editor-kit/osm-data into a Segment.

Other data sources

Implement OsmDataAdapter to chain ways from somewhere other than a loaded session:

import type { OsmDataAdapter, Segment } from '@osm-editor-kit/osm-way-chain'

const waysById = new Map<number, Segment>() // fill from your own source

const adapter: OsmDataAdapter = {
  getWay: async (wayId) => {
    const way = waysById.get(wayId)
    if (!way) throw new Error(`Way ${wayId} not found`)
    return way
  },
  // All ways that use this node
  getWaysForNode: async (nodeId) =>
    [...waysById.values()].filter((way) => way.nodeIds.includes(nodeId)),
}

License

MIT