Skip to content

Graph Lib

This landing page summarizes what @avensio/graph offers, how to install it in browser or Node environments, and where to find the deeper reference guides that now live in this docs.

@avensio/graph provides a flexible graph toolkit with strongly typed vertices, edges, comparators, and algorithms for building custom graph data structures, analyzing connectivity, and running traversal or optimization routines across browser and Node.js runtimes. The package keeps the footprint minimal: it depends on only two lightweight libraries, neither of which introduces additional transitive dependencies.

Key Features

  • Directed, undirected, and mixed graphs with density/connectedness helpers
  • Classical algorithms including DFS/BFS, Moore–Bellman–Ford, Yen-style k shortest paths, Kruskal-based MST, and layered topological sorting
  • Extensible AGraph base that accepts custom vertex/edge classes, comparators, and event payloads
  • Serialization hooks plus GraphView/JSONGraphView utilities for storing or visualizing graph state
  • Vertex emitters and a built-in TextEmitter for generating human-readable reports

Installation

Package managers

bash
pnpm add @avensio/graph
# npm install @avensio/graph
# yarn add @avensio/graph

Browser (IIFE + ESM)

html
<script src="https://unpkg.com/@avensio/graph@1.0.0/dist/graph.iife.js"></script>
<script>
  const { Graph, Vertex, Edge } = graph
  const a = new Vertex({ title: 'A' })
  const b = new Vertex({ title: 'B' })
  const instance = new Graph()
  instance.addVertex(a)
  instance.addVertex(b)
  instance.addEdge(new Edge({ from: a, to: b }))
  console.debug(instance.shortestPath(a, b))
</script>

<script type="module">
  import { Graph, Vertex, Edge } from 'https://unpkg.com/@avensio/graph@latest/dist/graph.es.js'
  const graph = new Graph()
  // ...
</script>

Node / Bundlers

ts
import { Graph, Vertex, Edge } from '@avensio/graph'

const graph = new Graph()
const a = graph.createVertex('A')
const b = graph.createVertex('B')
graph.addVertex(a)
graph.addVertex(b)
graph.createEdge(a, b, 'A -> B')

Quick Start

ts
import { Graph, Vertex, Edge } from '@avensio/graph'

const comparator = (v1, v2) => v1.uuid === v2.uuid ? 0 : v1.outdeg() < v2.outdeg() ? -1 : 1
const graph = new Graph({}, comparator)
const u = new Vertex({ title: 'U' })
const v = new Vertex({ title: 'V' })

graph.addVertex(u)
graph.addVertex(v)
graph.createEdge(u, v, 'U -> V', true, 3)

const path = graph.shortestPath(u, v)
console.log(path.map(node => node.title))

Explore Further

Built with VitePress – Released under the MIT License.