Registry / data / dijkstrajs

dijkstrajs

JSON →
library1.0.3jsnpmunverified

dijkstrajs is a lightweight, zero-dependency JavaScript library that provides a straightforward implementation of Dijkstra's single-source shortest-paths algorithm. Currently at version 1.0.3, the package was last published over three years ago, indicating a mature and stable codebase rather than active feature development. It is designed for use in Node.js environments and offers a simple API for finding the shortest path between two nodes in a weighted graph. While other Dijkstra implementations might offer performance optimizations like priority queues, dijkstrajs prioritizes simplicity and ease of integration for basic graph traversal needs. Developers should note its inherent limitation of not supporting negative edge weights, which is a fundamental constraint of Dijkstra's algorithm itself.

npm install dijkstrajs
INSTALL
IMPORT
SIG · DIJKSTRAJS
D
dijkstrajs
datajavascriptv1.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

findPath
import { findPath } from 'dijkstrajs'
import dijkstra from 'dijkstrajs'
The library exports an object with a 'findPath' method, not a default function. This applies to both ESM and CJS.
findPath (CommonJS)
const { findPath } = require('dijkstrajs')
const dijkstra = require('dijkstrajs')
For CommonJS, destructure the 'findPath' method from the required module object.

This example demonstrates how to define a weighted graph using an adjacency list and then use `findPath` to calculate the shortest path between specified start and end nodes.

import { findPath } from 'dijkstrajs'; const graph = { A: { B: 1, C: 4 }, B: { A: 1, C: 2, D: 5 }, C: { A: 4, B: 2, D: 1 }, D: { B: 5, C: 1 }, E: { F: 3 }, // Disconnected node F: { E: 3 } }; // Find the shortest path from node A to node D const pathAD = findPath(graph, 'A', 'D'); console.log('Path from A to D:', pathAD); // Expected: [ 'A', 'B', 'C', 'D' ] // Find the shortest path from node A to node E (unreachable) const pathAE = findPath(graph, 'A', 'E'); console.log('Path from A to E:', pathAE); // Expected: null (or similar indication of no path) // Example with different start/end const pathBD = findPath(graph, 'B', 'D'); console.log('Path from B to D:', pathBD); // Expected: [ 'B', 'C', 'D' ]
Debug
Known issues
gotchaDijkstra's algorithm, and consequently this library, does not correctly compute shortest paths if the graph contains edges with negative weights. For graphs with negative weights, consider algorithms like Bellman-Ford or SPFA.
fix
Ensure all edge weights in your graph are non-negative, or use an alternative algorithm for graphs with negative weights.
affects: >=1.0.0
gotchaThe library is a 'simple implementation' and does not explicitly state the use of an optimized data structure like a min-priority queue. For very large or dense graphs, performance might be slower than implementations that utilize such optimizations (e.g., O(E log V) vs. O(V^2)).
fix
For performance-critical applications with large graphs, benchmark this library against alternatives that explicitly mention priority queue optimizations.
affects: >=1.0.0
gotchaThe expected graph input format is an adjacency list represented as a JavaScript object, where keys are node names and values are objects mapping neighbor nodes to their respective edge weights. Deviating from this format will lead to incorrect results or errors.
fix
Refer to the quickstart example for the precise graph object structure required by `dijkstrajs`.
affects: >=1.0.0
deprecatedThe package has not been updated in over three years (last published 3+ years ago). While stable, this indicates a lack of active development, bug fixes, or new features. Users should be aware that new Node.js versions or JavaScript features might not be officially supported or tested.
fix
Consider testing thoroughly with newer Node.js runtimes. For projects requiring active maintenance or advanced features, explore more recently updated graph libraries.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , dijkstrajs__WEBPACK_IMPORTED_MODULE_0__.findPath) is not a function
Attempting to import `findPath` using a default import or a CommonJS `require` call that doesn't destructure the `findPath` property from the module object in an ESM context.
fix
Use a named import for ESM: `import { findPath } from 'dijkstrajs'`. For CommonJS, ensure proper destructuring: `const { findPath } = require('dijkstrajs')`.
TypeError: Cannot read properties of undefined (reading 'findPath')
This typically occurs in CommonJS environments when `require('dijkstrajs')` is assigned to a variable, and then `.findPath` is called on it, but the default export isn't the expected object, or the import path is incorrect.
fix
Verify the `require` statement accurately destructures `findPath`: `const { findPath } = require('dijkstrajs')`. Ensure the package is correctly installed.
Path not found (or similar message/null return for unreachable nodes)
The `findPath` function returns `null` or an empty path when the target node is unreachable from the source node within the given graph, or if the graph is disconnected.
fix
Validate that the source and target nodes exist in the graph and that there is a connected path between them. Handle the `null` return explicitly in your application logic.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
dijkstrajs — npm install dijkstrajs · libregistry