
Research
Malicious fezbox npm Package Steals Browser Passwords from Cookies via Innovative QR Code Steganographic Technique
A malicious package uses a QR code as steganography in an innovative technique.
graphology-dag
Advanced tools
Functions related to Directed Acyclic Graphs (DAGs) and to be used with graphology
.
npm install graphology-dag
Function returning whether the given directed graph contains at least one cycle.
Note that this function will also work with a disconnected graph.
import {hasCycle} from 'graphology-dag';
// Alternatively, to load only the relevant code:
import hasCycle from 'graphology-dag/has-cycle';
const graph = new DirectedGraph();
graph.mergeEdge(0, 1);
graph.mergeEdge(1, 2);
graph.mergeEdge(2, 3);
hasCycle(graph);
>>> false
graph.mergeEdge(3, 0);
hasCycle(graph);
>>> true
Function returning whether adding the given directed edge to a DAG will create an undesired cycle.
Note that this function expects a valid DAG and even if passing a cyclic graph could work it could also very well lead to undefined behavior ranging from an infinite loop to overkill memory usage.
Note finally that this function will also work with DAG forests (sets of disconnected DAGs living in the same graph instance).
import {willCreateCycle} from 'graphology-dag';
// Alternatively, to load only the relevant code:
import willCreateCycle from 'graphology-dag/will-create-cycle';
const graph = new DirectedGraph();
graph.mergeEdge(0, 1);
graph.mergeEdge(1, 2);
graph.mergeEdge(2, 3);
willCreateCycle(graph, 3, 0);
>>> true
willCreateCycle(graph, 0, 2);
>>> false
Function returning an array of nodes representing a possible topological ordering of the given DAG.
Note that this function will throw if given graph has any cycle, is able to work on mixed graphs containing only directed edges and can work on disconnected graphs (a DAG forest).
import {topologicalSort} from 'graphology-dag';
// Alternatively, to load only the relevant code:
import {topologicalSort} from 'graphology-dag/topological-sort';
const graph = new DirectedGraph();
graph.mergeEdge(0, 1);
graph.mergeEdge(1, 2);
graph.mergeEdge(2, 3);
topologicalSort(graph);
>>> ['0', '1', '2', '3']
Function returning an array of array of nodes representing the successive generations of the topological ordering of the given DAG.
Note that this function will throw if given graph has any cycle, is able to work on mixed graphs containing only directed edges and can work on disconnected graphs (a DAG forest).
import {topologicalGenerations} from 'graphology-dag';
// Alternatively, to load only the relevant code:
import {topologicalGenerations} from 'graphology-dag/topological-sort';
const graph = new DirectedGraph();
graph.mergeEdge(0, 1);
graph.mergeEdge(1, 2);
graph.mergeEdge(0, 3);
topologicalGenerations(graph);
>>> [[ '0' ], ['1', '3'], ['2']]
Function iterating over the given DAG's nodes in topological order using a callback function.
Note that this function will throw if given graph has any cycle, is able to work on mixed graphs containing only directed edges and can work on disconnected graphs (a DAG forest).
import {forEachNodeInTopologicalOrder} from 'graphology-dag';
// Alternatively, to load only the relevant code:
import {forEachNodeInTopologicalOrder} from 'graphology-dag/topological-sort';
const graph = new DirectedGraph();
graph.mergeEdge(0, 1);
graph.mergeEdge(1, 2);
graph.mergeEdge(2, 3);
forEachNodeInTopologicalOrder(graph, (node, attr, generationIndex) => {
// Note that generationIndex will be monotonically increasing from 0 to n.
console.log(node, attr, generationIndex);
});
Function iterating over the given DAG's generations, represented by an array of node keys, using a callback function.
Note that this function will throw if given graph has any cycle, is able to work on mixed graphs containing only directed edges and can work on disconnected graphs (a DAG forest).
import {forEachTopologicalGeneration} from 'graphology-dag';
// Alternatively, to load only the relevant code:
import {forEachTopologicalGeneration} from 'graphology-dag/topological-sort';
const graph = new DirectedGraph();
graph.mergeEdge(0, 1);
graph.mergeEdge(1, 2);
graph.mergeEdge(2, 3);
forEachTopologicalGeneration(graph, generation => {
console.log(generation);
});
0.4.1
attributes
in export.FAQs
Directed acyclic graph functions for graphology.
The npm package graphology-dag receives a total of 76,365 weekly downloads. As such, graphology-dag popularity was classified as popular.
We found that graphology-dag 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
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.
Application Security
/Research
/Security News
Socket detected multiple compromised CrowdStrike npm packages, continuing the "Shai-Hulud" supply chain attack that has now impacted nearly 500 packages.