ds-deps
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

ds-deps

Dead-simple dependency graph.

ds-deps provides a graph data structure for building dependency trees. It has facilities for declaring dependencies as well as querying for direct and transitive dependency/dependant relationships and topologically sorting the graph. The goal of the library is to provide the building blocks for more interesting things like dependency resolution for a DI frameworks.

This library is heavily inspired by Stuart Sierra's dependency library. In fact, it is little more than a partial port of that library from Clojure to JavaScript.

Usage

import { Graph } from 'ds-deps';

const g = new Graph();
g.dependOn('cake', 'eggs');
g.dependOn('cake', 'flour');
g.dependOn('eggs', 'chickens');
g.dependOn('flour', 'grain');
g.dependOn('chickens', 'grain');
g.dependOn('grain', 'soil');

g.dependsOn('cake', 'soil');
// -> true

g.dependsOn('grain', 'cake');
// -> false

g.topoSort();
// -> [ 'soil', 'grain', 'chickens', 'flour', 'eggs', 'cake' ]

/ds-deps/

    Package Sidebar

    Install

    npm i ds-deps

    Weekly Downloads

    6

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    9.19 kB

    Total Files

    9

    Last publish

    Collaborators

    • kendru