Socket
Socket
Sign inDemoInstall

dependency-graph

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dependency-graph

Simple dependency graph.


Version published
Weekly downloads
4.3M
decreased by-21.69%
Maintainers
1
Install size
11.2 kB
Created
Weekly downloads
 

Package description

What is dependency-graph?

The dependency-graph npm package is a simple library for creating a directed graph of dependencies and performing operations on it. It allows for adding nodes and dependencies, detecting cycles, and performing depth-first searches among other functionalities. This package is particularly useful for managing and analyzing dependencies in software projects, ensuring that dependency structures are acyclic and well-organized.

What are dependency-graph's main functionalities?

Creating a Dependency Graph

This feature allows for the creation of a new dependency graph and the addition of nodes and dependencies between them. In the code sample, a graph is created, and two nodes, 'A' and 'B', are added with a dependency from 'A' to 'B'.

const { DepGraph } = require('dependency-graph');
const graph = new DepGraph();
graph.addNode('A');
graph.addNode('B');
graph.addDependency('A', 'B');

Detecting Cycles

This feature checks if the dependency graph contains any cycles, which are sequences of dependencies that loop back on themselves. The code sample demonstrates how to check if the graph has any cycles.

const hasCycle = graph.hasCycle();

Performing Depth-First Search

This feature performs a depth-first search to find all dependencies of a given node. The code sample shows how to find all dependencies of node 'A'. This is useful for understanding the full set of dependencies that a particular node or module relies on.

const dependenciesOfA = graph.dependenciesOf('A');

Other packages similar to dependency-graph

Changelog

Source

0.2.0 (May 1, 2015)

  • Removed dependency on Underscore - thanks myndzi! (Fixes #1)

Readme

Source

Dependency Graph

Simple dependency graph

Overview

This is a simple dependency graph useful for determining the order to do a list of things that depend on certain items being done before they are.

To use, npm install dependency-graph and then require('dependency-graph').DepGraph

API

DepGraph

Nodes in the graph are just simple strings.

  • addNode(name) - add a node in the graph
  • removeNode(name) - remove a node from the graph
  • hasNode(name) - check if a node exists in the graph
  • addDependency(from, to) - add a dependency between two nodes (will throw an Error if one of the nodes does not exist)
  • removeDependency(from, to) - remove a dependency between two nodes
  • dependenciesOf(name, leavesOnly) - get an array containing the nodes that the specified node depends on (transitively). If leavesOnly is true, only nodes that do not depend on any other nodes will be returned in the array.
  • dependantsOf(name, leavesOnly) - get an array containing the nodes that depend on the specified node (transitively). If leavesOnly is true, only nodes that do not have any dependants will be returned in the array.
  • overallOrder(leavesOnly) - construct the overall processing order for the dependency graph. If leavesOnly is true, only nodes that do not depend on any other nodes will be returned.

Examples

var DepGraph = require('dependency-graph').DepGraph;

var graph = new DepGraph();
graph.addNode('a');
graph.addNode('b');
graph.addNode('c');

graph.addDependency('a', 'b');
graph.addDependency('b', 'c');

graph.dependenciesOf('a'); // ['c', 'b']
graph.dependenciesOf('b'); // ['c']
graph.dependantsOf('c'); // ['a', 'b']

graph.overallOrder(); // ['c', 'b', 'a']
graph.overallOrder(true); // ['c']

Keywords

FAQs

Last updated on 02 May 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc