
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
l1-path-finder
Advanced tools
A fast path planner for grids.
var ndarray = require('ndarray')
var createPlanner = require('l1-path-finder')
//Create a maze as an ndarray
var maze = ndarray([
0, 1, 0, 0, 0, 0, 0,
0, 1, 0, 1, 0, 0, 0,
0, 1, 0, 1, 1, 1, 0,
0, 1, 0, 1, 0, 0, 0,
0, 1, 0, 1, 0, 0, 0,
0, 1, 0, 1, 0, 0, 0,
0, 1, 0, 1, 0, 1, 1,
0, 0, 0, 1, 0, 0, 0,
], [8, 7])
//Create path planner
var planner = createPlanner(maze)
//Find path
var path = []
var dist = planner.search(0,0, 7,6, path)
//Log output
console.log('path length=', dist)
console.log('path = ', path)
Output:
path length= 31
path = [ 0, 0, 7, 0, 7, 2, 0, 2, 0, 4, 1, 4, 1, 6, 3, 6, 5, 6, 5, 4, 7, 4, 7, 6 ]
This module works in any node-flavored CommonJS environment, including node.js, iojs and browserify. You can install it using the npm package manager with the following command:
npm i l1-path-finder
The input to the library is in the form of an ndarray. For more information on this data type, check out the SciJS project.
var createPlanner = require('l1-path-finder')
var planner = createPlanner(grid)The default method from the package is a constructor which creates a path planner.
grid is a 2D ndarray. 0 or false-y values correspond to empty cells and non-zero or true-thy values correspond to impassable obstaclesReturns A new planner object which you can use to answer queries about the path.
Time Complexity O(grid.shape[0]*grid.shape[1] + n log(n)) where n is the number of concave corners in the grid.
Space Complexity O(n log(n))
var dist = planner.search(srcX, srcY, dstX, dstY[, path])Executes a path search on the grid.
srcX, srcY are the coordinates of the start of the path (source)dstX, dstY are the coordiantes of the end of the path (target)path is an optional array which receives the result of the pathReturns The distance from the source to the target
Time Complexity Worst case O(n log²(n)), but in practice much less usually
l1-path-finder is probably the fastest JavaScript library for finding paths on uniform cost grids. Here is a chart showing some typical comparisons (log-scale):
You can try out some of the benchmarks in your browser here, or you can run them locally by cloning this repo. Data is taken from the grid path planning challenge benchmark.
(c) 2015 Mikola Lysenko. MIT License
FAQs
Fast shortest path finder for grids
The npm package l1-path-finder receives a total of 128 weekly downloads. As such, l1-path-finder popularity was classified as not popular.
We found that l1-path-finder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.