dependency-graph
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Dependency-Graph is an effective JavaScript (JS) tool offering a simple way to manage and organise dependencies, which are relations between different nodes or tasks. It's particularly useful when dealing with a collection of tasks that rely upon the completion of other tasks. By mapping these dependencies, you can efficiently determine the best order to perform tasks without encountering unfulfilled prerequisites.
To use Dependency-Graph, follow these steps. Firstly, you should install the npm package using the following code:
npm install dependency-graph
Once it's installed, require it in your JS file, like this:
var DepGraph = require('dependency-graph').DepGraph;
After requiring the package, you can create a new dependency graph:
var graph = new DepGraph();
Then, you can add nodes and dependencies:
graph.addNode('a');
graph.addNode('b');
graph.addDependency('a', 'b'); // 'a' depends on 'b'
You may retrieve the dependencies of a node using the dependenciesOf
method:
graph.dependenciesOf('a'); // Returns: ['b']
Additionally, the overallOrder
function is available to determine the overarching processing order within the dependency graph:
graph.overallOrder(); // Returns: ['b', 'a']
For more complex operations, like silencing errors in case of dependency cycles, a circular graph can be set:
var circularGraph = new DepGraph({ circular: true });
circularGraph.addDependency('a', 'b');
circularGraph.addDependency('b', 'a'); // Circular: 'a' depends on 'b', 'b' depends on 'a'
These are basic operations to manipulate dependency graphs, but other actions, like removing nodes and dependencies, cloning the graph, and setting or getting node data, are also available.
You can find the documentation for Dependency-Graph within the README file of the git repository (git://github.com/jriecken/dependency-graph.git). This README provides a top-level overview of the package functionality list, explaining how to accomplish tasks such as adding nodes, removing nodes, setting and getting a node's data, determining the graph's size, and more.