Socket
Book a DemoInstallSign in
Socket

@bedard/pathfinder

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bedard/pathfinder

A* path finding algorithm

0.1.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

@bedard/pathfinder

Build status Codecov NPM Bundle size License

This project is a simple javascript implementation of the A* search algorithm. It was mainly built to get my feet wet with Solid.js.

View sandbox →

Basic usage

Use findPath to find the shortest path between two points within a two-dimensional matrix.

import { findPath } from '@bedard/pathfinder'

const maze = [
  [0, 0, 0, 0, 0],
  [1, 1, 1, 1, 0],
  [0, 0, 0, 0, 0],
  [0, 1, 1, 1, 1],
  [0, 0, 0, 0, 0],
]

const solution = findPath({
  data: maze,
  from: { row: 0, col: 0 },
  to: { row: 4, col: 4 },
})

console.log(solution) // [{ row, col }, ...]

To optimize the solution, an optional heuristic function can be used. Included with this library are euclidean and manhattan distance helpers. When no heuristic function is defined, it will use Dijkstra's algorithm.

import { euclidean, findPath } from '@bedard/pathfinder'

findPath({
  data,
  from,
  to,
  heuristic: euclidean,
})

License

MIT

Copyright (c) 2024-present, Scott Bedard

FAQs

Package last updated on 22 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.