0.0.1 • Published 2 years ago

@datastructures/graph v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@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.