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.
graphology-operators
Advanced tools
Miscellaneous operators to be used with graphology
.
npm install graphology-operators
Unary
Binary
Cast
Return a graph's subgraph containing the given nodes and their relevant edges.
import {subgraph} from 'graphology-operators';
// Alternatively, to load only the relevant code:
import subgraph from 'graphology-operators/subgraph';
// From an array of nodes
const sub = subgraph(graph, ['John', 'Mary', 'Sue']);
// From a set of nodes
const sub = subgraph(graph, new Set(['John', 'Mary', 'Sue']));
// From a filtering function
const sub = subgraph(graph, function (key, attr) {
return key.startsWith('J') || attr.color === 'red';
});
Arguments
Reverse the given graph's directed edges.
import {reverse} from 'graphology-operators';
// Alternatively, to load only the relevant code:
import reverse from 'graphology-operators/reverse';
const reversedGraph = reverse(graph);
Arguments
Returns the disjoin union of the given graphs. To do so, the function will relabel your nodes & edges so both graphs can remain disjoint.
import {disjointUnion} from 'graphology-operators';
// Alternatively, to load only the relevant code:
import disjointUnion from 'graphology-operators/disjoint-union';
const R = disjointUnion(G, H);
Arguments
Returns the union of the given graphs. Nodes & edges present in both graph will have their attributes merges with precedence given to the second graph.
import {union} from 'graphology-operators';
// Alternatively, to load only the relevant code:
import union from 'graphology-operators/union';
const R = union(G, H);
Arguments
Returns the directed version of the given graph where any undirected edge will be now considered as mutual.
Note that you can pass a function to merge edge attributes in case of mixed edges conflicts. This can be useful to sum weights and so on...
If an already directed graph is passed, the function will only return a copy of it.
If passing a multi graph, undirected edges will only be converted as pairs ofmutual ones and will never be merged.
import {toDirected} from 'graphology-operators';
// Alternatively, to load only the relevant code:
import toDirected from 'graphology-operators/to-directed';
const directedGraph = toDirected(graph);
// Using a merging function
const directedGraph = toDirected(graph, (currentAttr, nextAttr) => {
return {
...currentAttr,
weight: currentAttr.weight + nextAttr.weight
};
});
Arguments
Returns the given graph as mixed.
If an already mixed graph is passed, the function will only return a copy of it.
import {toMixed} from 'graphology-operators';
// Alternatively, to load only the relevant code:
import toMixed from 'graphology-operators/to-mixed';
const mixedGraph = toMixed(graph);
Returns the given graph as multi.
If an already multi graph is passed, the function will only return a copy of it.
import {toMulti} from 'graphology-operators';
// Alternatively, to load only the relevant code:
import toMulti from 'graphology-operators/to-multi';
const mixedGraph = toMulti(graph);
Returns the simple version of the given multigraph where we only keep a single edge of each type between nodes.
Note that you can pass a function to merge edge attributes in case of mutual edges or mixed edges conflicts. This can be useful to sum weights and so on...
If an already simple graph is passed, the function will only return a copy of it.
import {toSimple} from 'graphology-operators';
// Alternatively, to load only the relevant code:
import toSimple from 'graphology-operators/to-simple';
const simpleGraph = toSimple(multiGraph);
// Using a merging function
const simpleGraph = toSimple(graph, (currentAttr, nextAttr) => {
return {
...currentAttr,
weight: currentAttr.weight + nextAttr.weight
};
});
Arguments
Returns the undirected version of the given graph where any directed edge will be now considered as undirected.
Note that you can pass a function to merge edge attributes in case of mutual edges or mixed edges conflicts. This can be useful to sum weights and so on...
If an already undirected graph is passed, the function will only return a copy of it.
If passing a multi graph, directed edges will only be converted as undirected ones and will never be merged.
import {toUndirected} from 'graphology-operators';
// Alternatively, to load only the relevant code:
import toUndirected from 'graphology-operators/to-undirected';
const undirectedGraph = toUndirected(graph);
// Using a merging function
const undirectedGraph = toUndirected(graph, (currentAttr, nextAttr) => {
return {
...currentAttr,
weight: currentAttr.weight + nextAttr.weight
};
});
Arguments
FAQs
Miscellaneous operators for graphology.
The npm package graphology-operators receives a total of 12,035 weekly downloads. As such, graphology-operators popularity was classified as popular.
We found that graphology-operators 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.