graphology-utils
Advanced tools
Comparing version 1.4.0 to 1.5.0
{ | ||
"name": "graphology-utils", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Miscellaneous utils for graphology.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -172,3 +172,3 @@ [![Build Status](https://travis-ci.org/graphology/graphology-utils.svg)](https://travis-ci.org/graphology/graphology-utils) | ||
* **graph** *Graph*: source graph. | ||
* **nodes** *array|Set*: the subgraph's array or set of nodes. | ||
* **nodes** *array|Set|function*: the array, set or function defining the subgraph's nodes. | ||
@@ -12,5 +12,5 @@ /** | ||
* @param {Graph} graph - Graph containing the subgraph. | ||
* @param {array} nodes - Array or set of the nodes to keep. | ||
* @return {Graph} | ||
* @param {array} nodes - Array, set or function defining the nodes wanted in the subgraph. | ||
*/ | ||
module.exports = function subGraph(graph, nodes) { | ||
@@ -26,8 +26,17 @@ var nodesSet; | ||
} | ||
else if (typeof nodes === 'function') { | ||
nodesSet = new Set(); | ||
graph.forEachNode(function(key, attrs) { | ||
if (nodes(key, attrs)) { | ||
nodesSet.add(key); | ||
} | ||
}); | ||
} | ||
else { | ||
throw new Error('graphology-utils/subgraph: given "nodes" is neither an array nor a set.'); | ||
throw new Error( | ||
'The argument "nodes" is neither an array, nor a set, nor a function.' | ||
); | ||
} | ||
if (nodesSet.size === 0) | ||
return subGraphResult; | ||
if (nodesSet.size === 0) return subGraphResult; | ||
@@ -34,0 +43,0 @@ var insertedSelfloops = new Set(); // Useful to check if a selfloop has already been inserted or not |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12457
230