🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

graphlib

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphlib

A directed and undirected multi-graph library

2.1.8
latest
Source
npm
Version published
Weekly downloads
2.4M
12.37%
Maintainers
2
Weekly downloads
 
Created

What is graphlib?

The graphlib package is a JavaScript library for creating and manipulating directed and undirected graphs. It provides a variety of methods for graph creation, traversal, and analysis, making it a versatile tool for working with graph data structures.

What are graphlib's main functionalities?

Graph Creation

This feature allows you to create a new graph, add nodes, and create edges between nodes. The code sample demonstrates how to create a graph, add two nodes 'a' and 'b', and create an edge from 'a' to 'b'.

const graphlib = require('graphlib');
const g = new graphlib.Graph();
g.setNode('a');
g.setNode('b');
g.setEdge('a', 'b');
console.log(g.nodes()); // ['a', 'b']
console.log(g.edges()); // [{ v: 'a', w: 'b' }]

Graph Traversal

This feature allows you to traverse the graph using depth-first search (DFS). The code sample demonstrates how to perform a DFS starting from node 'a' and prints the traversal order.

const graphlib = require('graphlib');
const g = new graphlib.Graph();
g.setNode('a');
g.setNode('b');
g.setNode('c');
g.setEdge('a', 'b');
g.setEdge('b', 'c');
const dfs = graphlib.alg.dfs(g, ['a']);
console.log(dfs); // [{ v: 'a' }, { v: 'b' }, { v: 'c' }]

Graph Analysis

This feature allows you to analyze the graph for properties such as acyclicity. The code sample demonstrates how to check if the graph contains cycles and prints the result.

const graphlib = require('graphlib');
const g = new graphlib.Graph();
g.setNode('a');
g.setNode('b');
g.setNode('c');
g.setEdge('a', 'b');
g.setEdge('b', 'c');
g.setEdge('c', 'a');
const isAcyclic = graphlib.alg.isAcyclic(g);
console.log(isAcyclic); // false

Other packages similar to graphlib

Keywords

graph

FAQs

Package last updated on 03 Dec 2019

Did you know?

Socket

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