dag-visitor
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

dag-visitor

A generic visitor library for directed-acyclic graphs in JavaScript. The purpose of this library is to use best practices for traversing a graph. It avoids using recursion to enable processing of large graphs.

Example usage

// Setup a DAG
const a = { id: 'a', children: []};
const b = { id: 'b', children: []};
a.children.push(b);

const dfsVisitor = new DfsVisitor(
    (node) => { 
        console.log(`previsit: ${node.id}`); 
        return node.children; 
    },
    (node) => { console.log(`postvisit: ${node.id}`); });

dfsVisitor.visit([a, b]);

// previsit: a
// previsit: b
// postvisit: b
// postvisit: a

Dependencies (0)

    Dev Dependencies (10)

    Package Sidebar

    Install

    npm i dag-visitor

    Weekly Downloads

    3

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    4.14 kB

    Total Files

    7

    Last publish

    Collaborators

    • seanzer