This package has been deprecated

Author message:

deprecated

dager

2.0.1 • Public • Published

dager

A directed acyclic graph with constant time access to a node's sources and targets (dependencies and dependants).

  • Node identifiers are strings.
  • There is either one or no edge between any two nodes.
  • Nodes and edges can hold objects.

Example

var dager = require('dager');
var dag = dager();
 
dag.edge('a', 'b', 'a->b');
dag.edge('b', 'c', 'b->c');
dag.edge('a', 'd', 'a->d');
 
dag.get('a', 'd') // 'a->d'
 
dag.from('a'); // { b: 'a->b', d: 'a->d' }
dag.from('b'); // { c: 'b->c' }
dag.to('b'); // { a: 'a->b' }
dag.to('a'); // {}
 
dag.edge('c', 'a', 'c->a'); // Error: Failed DAG add. No cycles allowed.

API

dager()

Create a new DAG.

dag.get(source [, target])

Get the value of a node or edge.

dag.edge(source, target [, edgeValue])

Add an edge to the dag from the source node to the target node. Source and target node identifiers must be strings and are added to the graph if not yet in it.

dag.node(node [, nodeValue])

Node setter.

dag.get('foo'); // undefined
dag.node('foo', 75); // 75
dag.get('foo'); // 75

dag.from(node)

Get all edges from a node. Returns an object where the keys are the targets of the edges to the node and the values are the values of the edges.

Don't modify the returned object before cloning it or you'll mess up the graph.

dag.to(node)

Get all edges to a node. Returns an object where the keys are the sources of the edges to the node and the values are the values of the edges.

Don't modify the returned object before cloning it or you'll mess up the graph.

Readme

Keywords

Package Sidebar

Install

npm i dager

Weekly Downloads

0

Version

2.0.1

License

ISC

Last publish

Collaborators

  • npm