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

@casko/pathfinding

v1.0.0-pre

Published

Grid pathfinding algorithms for 2D maps, written in TypeScript.

Readme

Pathfinding

@casko/pathfinding is a TypeScript library for 2D grid pathfinding. It provides a shared typed API and implementations of:

  • A*
  • BFS
  • Dijkstra
  • Greedy Best-First Search
  • Jump Point Search
  • Theta*

Install

npm install @casko/pathfinding

Demo

Run the visual browser demo locally:

npm install
npm run demo

Create a static demo bundle:

npm run demo:build

Quick Start

import { astar, type GridLike } from "@casko/pathfinding";

const grid: GridLike = {
  isUniformCost: true,
  isWithinBounds: ({ x, y }) => x >= 0 && x < 10 && y >= 0 && y < 10,
  isWalkableAt: ({ x, y }) => !(x === 4 && y >= 2 && y <= 7),
  getCost: () => 1,
};

const result = astar(grid, {
  start: { x: 0, y: 0 },
  goal: { x: 9, y: 9 },
  diagonalMovement: "always",
});

if (result.found) {
  console.log(result.path, result.cost);
}

API

All algorithms are pure functions that accept a GridLike and SearchOptions, then return a SearchResult.

GridLike

interface GridLike {
  isWithinBounds(coordinate: GridCoordinate): boolean;
  isWalkableAt(coordinate: GridCoordinate): boolean;
  getCost(from: GridCoordinate, to: GridCoordinate): number;
  hasLineOfSight?(from: GridCoordinate, to: GridCoordinate): boolean;
  isUniformCost?: boolean;
}

SearchOptions

interface SearchOptions {
  start: GridCoordinate;
  goal: GridCoordinate;
  diagonalMovement?: "never" | "always" | "ifAtMostOneObstacle" | "onlyWhenNoObstacles";
  heuristic?: Heuristic;
  heuristicWeight?: number;
  maxIterations?: number;
}

SearchResult

interface SearchResult {
  found: boolean;
  path: GridCoordinate[];
  cost: number;
  visited: number;
  expanded: number;
  metadata: {
    algorithm: string;
    frontierPeak: number;
    pathLength: number;
  };
}

Heuristics

The package exports:

  • manhattan
  • euclidean
  • octile
  • defaultHeuristic

If no heuristic is provided, orthogonal searches use Manhattan distance and diagonal-enabled searches use Octile distance.

Diagonal Movement

Supported diagonal movement policies:

  • never
  • always
  • ifAtMostOneObstacle
  • onlyWhenNoObstacles

Algorithm Notes

  • bfs is optimal only for unweighted movement.
  • dijkstra finds the least-cost path for non-negative weights.
  • astar matches Dijkstra’s optimality when the heuristic is admissible.
  • greedyBestFirst is often faster but may return non-optimal paths.
  • jumpPointSearch only supports uniform-cost grids. Set grid.isUniformCost to false for weighted grids so unsupported usage fails fast.
  • thetaStar uses grid.hasLineOfSight when available. Otherwise it falls back to a built-in Bresenham-style visibility check over walkable cells.

Errors And Failure Cases

  • Invalid or non-walkable start/goal coordinates throw an error.
  • When no route exists, algorithms return found: false, an empty path, and cost: Infinity.