@datastructures/graph
TypeScript icon, indicating that this package has built-in type declarations

0.0.1Β β€’Β PublicΒ β€’Β Published

@datastructures/graph πŸ“ˆπŸ“‰

Typed with TypeScript npm version

A minimal functional typed implementation of a graph. πŸ¦„

A collection of vertices related by edges


Install

yarn add @datastructures/graph -D

Usage

import { graph, vertex } from '@datastructures/graph'
const chart = graph().addVertex('foo').addVertex('bar')
chart.addEdge('foo', 'bar')
const viewChart = chart.render()
// => { directed: false, vertices: [ { key: 'foo', ...}, { key: 'bar', ...} ], edges: ['foo-bar' ]}
const printChart = chart.print()

API

Vertex

A individual vertice

key: a string vertex identifier

siblings: an array of vertices

addSibling: a methode for adding siblings to a vertex

ex: const item = vertex('foo').addSibling('bar')

Methods

addVertex: adds a vertex to the graph

ex: const chart = graph().addVertex('foo')

addEdge: adds an edge to the Graph

ex: const chart = graph().addVertex('foo').addEdge('bar').addEdge('foo', 'bar')

render: renders the graph

ex: const chart = graph().addVertex('foo').addEdge('bar').addEdge('foo', 'bar').render()

print: renders a string output of the graph

ex: const chart = graph().addVertex('foo').addEdge('bar').addEdge('foo', 'bar').print()


Data Structures πŸ¦„

Basic. Functional. Typed. Data Structures.

Functional typed data structures offering structure clarity and simplicity.


View other data structures.

/@datastructures/graph/

    Package Sidebar

    Install

    npm i @datastructures/graph

    Weekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    8.69 kB

    Total Files

    6

    Last publish

    Collaborators

    • yowainwright