1.0.6 • Published 5 years ago

simplegraphjs v1.0.6

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage Status npm version

SimpleGraph.js

A very simple graph implementation for use in JS or Typescript, using an adjacency matrix.

Zero dependencies.

Installing

Simply:

yarn add simplegraphjs

Then import the graph:

import {Graph} from "simplegraphjs";

Usage

Load the graph up with edges using:

import {Graph} from "simplegraphjs";
const graph = new Graph();
graph.addEdge('1', '2');
graph.addEdge('2', '3');
graph.addEdge('2', '4');
graph.addEdge('4', '5');

Then run a breadth first search like this:

graph.breadthFirstSearch('1', '3')

You will then get back an ISearchResult, which looks like this:

{
   "path": ["2", "3"],
   "success": true,
   "visited": 2
}

Todo

  • Option to switch to using an adjacency list.
  • Depth First Search traversal.
  • Support for Weighted Graphs.
  • Support for Directed Graphs.

License

This code is under the MIT licence.