dewdrops
v1.0.2
Published
Shortest path between any two nodes in any connected graph. BFS and Dijkstra. Zero dependencies.
Maintainers
Readme
dewdrops
Shortest path between any two nodes in any connected graph. BFS and Dijkstra. Zero dependencies.
npm install dewdropsWhat it dews
dewdrops is an overlay, not a database. You bring the data. dewdrops brings the topology.
Point it at any flat data structure with nodes and relationships — a skill tree, a supply chain, a hospital floor plan, a freight network — and dewdrops superimposes a weighted graph on top of it. Your data stays your data. dewdrops is the lens.
Usage
import { TreeTopologyHeuristics, TreeNode } from 'dewdrops'
const graph: Record<string, TreeNode> = {
a: { id: 'a', connections: ['b', 'c'], weights: { b: 1, c: 4 } },
b: { id: 'b', connections: ['d'], weights: { d: 2 } },
c: { id: 'c', connections: ['d'], weights: { d: 1 } },
d: { id: 'd', connections: [], weights: {} },
}
// Weighted shortest path (Dijkstra)
const result = TreeTopologyHeuristics.findPath(graph, 'a', 'd')
console.log(result.path) // ['a', 'c', 'd']
console.log(result.distance) // 5
// Nearest node from a set of candidates
const nearest = TreeTopologyHeuristics.findNearest(graph, 'a', ['c', 'd'])
console.log(nearest.targetId) // 'c'
console.log(nearest.distance) // 4API
TreeNode
interface TreeNode {
id: string
connections: string[]
weights: Record<string, number>
}PathResult
interface PathResult {
distance: number // -1 if unreachable
path: string[] // empty if unreachable
}NearestResult
interface NearestResult {
targetId: string
distance: number
path: string[]
}TreeTopologyHeuristics.findPath(graph, start, target)
Finds the shortest path between two nodes. Auto-selects BFS (unweighted) or Dijkstra (weighted) based on the graph. Returns PathResult with distance: -1 if unreachable.
TreeTopologyHeuristics.findNearest(graph, start, candidates)
Finds the closest node from a list of candidates. Returns NearestResult.
TreeTopologyHeuristics.calculateGraphDistance(graph, start, target)
Returns the shortest distance as a float. Returns -1 if unreachable.
The two layers
dewdrops always works on two layers:
- Your flat data — the source of truth. JSON, a database, a game export, whatever you have.
- The graph — what dewdrops builds from it. Nodes, edges, weights.
dewdrops reads both. The flat data is never discarded — it's the context the graph lives on top of. When you apply constraints or query paths, you're querying the overlay, not replacing the source.
Zero dependencies
No runtime dependencies. BFS and Dijkstra implemented from scratch. Works in Node, browsers, and any TypeScript environment.
Part of Dew
dewdrops is the TypeScript distro of Dew — intent-driven graph routing for any connected system.
"What do you need it to dew?"
