Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
graph-builder
Advanced tools
A graph builder library for modeling, and traversing abstract graph structures.
This is a (incomplete) port of the guava graph library.
The main entry point for building the graph are the
GraphBuilder
for building a
MutableGraph
and
ValueGraphBuilder
for building a
MutableValueGraph
.
There is also a traverser which can perform different types of traversal of any graphs/trees (that implement SuccessorFunction, which all the Graphs created by the GraphBuilder do).
Create an undirected Mutablegraph:
const { GraphBuilder } = require('graph-builder');
const graph = GraphBuilder.undirected().allowsSelfLoops(true).build();
Add some nodes:
graph.addNode("bread");
Add some edges (silently adds nodes too):
graph.putEdge("bread", "bread");
graph.putEdge("chocolate", "peanut butter");
graph.putEdge("peanut butter", "jelly");
Remove an edge:
graph.removeEdge("chocolate", "peanut butter");
Everything returned is iterable.
Get connected nodes:
for (const n of graph.adjacentNodes("peanut butter")) {
console.log(n);
}
// prints:
// chocolate
// jelly
Get all the edges:
for (const e of graph.edges()) {
console.log(e.nodeU, ' => ', e.nodeV);
}
// prints:
// bread => bread
// peanut butter => chocolate
// jelly => peanut butter
Get all edges connected to "peanut butter":
for (const e of graph.incidentEdges("peanut butter")) {
console.log(e.nodeU, ' => ', e.nodeV);
}
// prints:
// chocolate => peanut butter
// jelly => peanut butter
Get all the successors/predecessors of "peanut butter" (in an undirected graph, these are the same):
for (const n of graph.successors("peanut butter")) {
console.log(n);
}
// prints:
// chocolate
// jelly
for (const n of graph.predecessors("peanut butter")) {
console.log(n);
}
// prints:
// chocolate
// jelly
Or for a directed graph:
const graph = GraphBuilder.directed().allowsSelfLoops(true).build();
graph.putEdge("bread", "bread");
graph.putEdge("chocolate", "peanut butter");
graph.putEdge("peanut butter", "jelly");
for (const n of graph.successors("peanut butter")) {
console.log(n);
}
// prints:
// jelly
for (const n of graph.predecessors("peanut butter")) {
console.log(n);
}
// prints:
// chocolate
The traversers return iterators.
Traverse a graph that looks like this (numbered breadth first):
1 2
| \ |
3 4--5
|
6
const { GraphBuilder, Traversers } = require('graph-builder');
const graph = GraphBuilder.directed().allowsSelfLoops(true).build();
graph.putEdge(1, 3);
graph.putEdge(1, 4);
graph.putEdge(2, 5);
graph.putEdge(4, 5);
graph.putEdge(3, 6);
Iterate breadth first:
const nodeIterator = Traversers.forGraph(graph).breadthFirst(1, 2); // starting from root nodes, 1 & 2
console.log(Array.from(nodeIterator).join(', '));
// prints: 1, 2, 3, 4, 5, 6,
Iterate depth first preorder:
const nodeIterator = Traversers.forGraph(graph).depthFirstPreOrder(1, 2); // starting from root nodes, 1 & 2
console.log(Array.from(nodeIterator).join(', '));
// prints: 1, 3, 6, 4, 5, 2
Iterate depth first postorder:
const nodeIterator = Traversers.forGraph(graph).depthFirstPostOrder(1, 2); // starting from root nodes, 1 & 2
console.log(Array.from(nodeIterator).join(', '));
// prints: 6, 3, 5, 4, 1, 2
See the full API documentation for usage.
Full typescript
typings are also provided.
FAQs
A graph builder library for modeling abstract graph structures.
The npm package graph-builder receives a total of 39 weekly downloads. As such, graph-builder popularity was classified as not popular.
We found that graph-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.