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

@flatten-js/spatial-graph

v0.1.0

Published

Spatial graph built on graphology and @flatten-js/core: nodes are 2D points, edges are segments.

Readme

@flatten-js/spatial-graph

A 2D spatial graph on top of graphology and @flatten-js/core. Nodes are points ([x, y] tuples), edges are segments. It is useful for circulation and corridor networks, floor-plan analysis and other planar line networks.

Install

npm install @flatten-js/spatial-graph @flatten-js/core

@flatten-js/core is a peer dependency, so your app and this library share one copy of Point and Segment.

The package ships both ES modules and CommonJS, with TypeScript declarations for each. It requires Node.js 22 or later.

Usage

import { Point, Segment } from '@flatten-js/core';
import { SpatialGraph } from '@flatten-js/spatial-graph';

const graph = new SpatialGraph({
  segments: [
    new Segment(new Point(0, 0), new Point(10, 0)),
    new Segment(new Point(10, 0), new Point(10, 10)),
  ],
});

graph.getJunctions();
graph.getShortestPath([0, 0], [10, 10]); // Segment[]
graph.findNearestEdge(new Point(4, 1));

API overview

SpatialGraph extends graphology's Graph. Main groups of methods:

  • Build: addSegment(s), addVertex, union, splitEdge, getSubgraph
  • Query: getNodes, getEdges, getSegments, getJunctions, getStubs, getPointNeighbors
  • Nearest and paths: findNearestEdge, getClosestNodeToPoint, projectPointOnClosestEdge, getShortestPath, findPaths, findIsolatedPaths
  • Edit: moveNode(s), collapsePointInto, removeStubPoint, removeEdge(s), removePoint(s), removeSegment
  • Orthogonality: hasOrthogonalEdges, getNodesWithOrthogonalEdges

Geometry helpers (pointsEqual, getPointDistance, findIntersection, nearestPointOnSegment, projectPointOnSegment, ...) and the types (NxPoint, NxEdge, NodeAttributes, EdgeAttributes, ...) are exported from the package root.

The graph lives on a coordinate grid: points are rounded to COORDINATE_PRECISION decimals (0 by default) to build node keys, so points that round to the same key are the same node. Helpers that return points (fromFlattenPoint, findIntersection, projectPointOnSegment, ...) snap their results to the same grid; checks such as isPointOnSegment and the validation inside findIntersection use exact coordinates. findLineIntersection returns the exact intersection of the lines through two edges.

Development

pnpm install
pnpm typecheck
pnpm test
pnpm build           # tsdown -> dist/ (ESM + CJS + .d.ts)
pnpm check:package   # publint + are-the-types-wrong

Sources are ESM with .js extensions on relative imports (nodenext).

Releasing

Releases are published from GitHub Actions with npm trusted publishing (OIDC, no npm token), and npm generates provenance automatically.

  1. Bump version in package.json and merge to main.

  2. Tag the release and push the tag. The tag must match the version:

    git tag v0.1.0
    git push origin v0.1.0
  3. The release workflow (.github/workflows/publish.yml) checks the tag, runs typecheck, tests, build and package checks, then runs npm publish.

License

MIT