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 🙏

© 2025 – Pkg Stats / Ryan Hefner

h-pkit

v0.1.0

Published

Fast, small, portable, low-effort, zero-dependency pathfinding kit for 2D square-grid maps

Readme

h-pkit

Overview

Fast, small, portable, low-effort, zero-dependency pathfinding kit for 2D square-grid maps

More verbose overview

h-pkit (halbu's pathfinding kit) is a Typescript pathfinding library. It implements the A* pathfinding algorithm, allows for considerable customisation, and supplements it with some nice-to-have extensions (preference for line-of-sight pathing where possible, multi-pass string-pulling algorithm for path smoothing and naturalisation). It is intended for use in any game, simulation or other application that models space with a two-dimensional grid.

It has been designed to require no coupling to your application's data structures or code, and minimal effort to incorporate into a project. The average user should be able to import the package and start generating paths with no further setup or configuration.

Usage

Let's assume our application models a map with a 2D array of cells which have a boolean property walkable:

let hpkit = new HPKit();
let path = hpkit.getPath(4, 3, 15, 17, (x, y) => this.map[x][y].walkable)

The first four parameters are origin XY and goal XY. The fifth parameter is the callback that h-pkit will use to test whether a location is passable. getPath will return an array of [number, number] representing the optimal path to the goal, or null if no path exists.

Installation

h-pkit is distributed as a hybrid module for both ESM and CJS. Install with npm i h-pkit and then either import or require it, whichever you prefer.

  • import { HPKit } from 'h-pkit';
  • let { HPKit } = require('hpkit');

Configuration

h-pkit exposes methods for configuring heuristics, movement weights, limits and convenience functionality: | Option | Acceptable Values | Default | Method | | ----------- | ----------- | ----------- | --- | | diagonal movement| true, false | true | allowDiagonals(boolean)| | heuristic | euclidean, manhattan, octile, chebyshev | euclidean | setHeuristic(string) | cardinal/diagonal movement costs | any two numbers| 1, sqrt(2)| setMoveCosts(number, number) | maximum path cost | any positive number or 0 (no max) | no max | setMaxCost(number) | maximum path moves | any positive number or 0 (no max) | no max | setMaxMoves(number) | straight-line path preference| true, false| false| preferStraightLinePath(boolean) | string-pull path postprocessing| true, false| false| applyStringPulling(boolean)

Certain options are mutually exclusive: straight-line preference and string-pulling cannot be enabled if you have disabled diagonal movement. h-pkit will throw an error if incompatible configuration options are selected.

Considerations

Co-ordinate values must be zero or greater. The closed list is implemented with a map of integers for fast lookup, and nodes generate keys via the function id() => (x << 16) | y, which requires that x and y are >=0 in order to guarantee uniqueness.

As h-pkit is decoupled from your implementation, it does not know the dimensions of your graph, and if left to its own devices may path out of bounds when searching. If your map has impassable cells at its edges this is a non-issue; if not, you can express your boundary constraints as part of the callback:

hpkit.getPath(
  2, 2, 5, 5,
  (x, y) => x >= 0 && y >= 0 && x < w && y < h && map[x][y].walkable
)