
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
connection-paths
Advanced tools
Determine if two things are connected (e.g. network nodes) and generate a list of possible paths
Determine if two things are connected (e.g. network nodes) and generate a list of possible paths. For example, if A connects to B and C, B connects to C and D, and C connects to D and A, then A can connect to D via an infinite number of paths, assuming a thing is allowed to reconnect to previous things in the path.
opt
)Instantiate Connections
opt
- An options object
source
- An array of arrays of two strings or URL or file system path to a CSV file that maps sources to destinationshasHeader
- (Optional) Whether or not source
has a header. If true
, the first row will be removed. Defaults to false
.Example
var Connections = require('node-connection-paths'),
connections = Connections(
{
hasHeader: true,
source: [['A','B'], ['A','C'], ['B','C'], ['B','D'], ['C','D'], ['C','A']]
}
);
source
, cb
)Get the destinations of a source
opt
- A sourceerr
, array destinations
) cb
- A function to be executed after the destinations are collectedExample
connections.getDestinations('A', function(err, destinations) {
if (err){ throw err; }
console.log(destinations); //[ 'B', 'C' ]
});
opt
, cb
)Generate possible paths between a source and destination
opt
- An options object
source
- A sourcedestination
- A destinationreverse
- Whether or not a node is allowed to connect to the previous node. Defaults to false
.revisit
- Whether or not a node is allowed to connect to any previous nodes. Defaults to false
.format
- (Optional) If "string", paths
will be an array of strings. If "array", paths
will be an array of arrays of strings. Defaults to "array".max
- (Optional) The maximum number of paths to generate. Defaults to 100.depth
queue
- (Optional) Concurrency limit for recursive operations. Defaults to 500.recursion
- (Optional) Maximum path recursion. Defaults to 5.err
, array{string} | array{array{string}} paths
) cb
- A function to be executed after the paths are generatedExample
connections.getPaths(
{
source: 'A',
destination: 'D',
reverse: true,
revisit: true,
format: 'string',
max: 2,
depth: {
queue: 10,
recursion: 3
}
}, function(err, paths) {
if (err) { throw err; }
console.log(paths); //[ 'A,B,D', 'A,C,D' ]
}
);
opt
, cb
)Determine if a source and destination are connected. Note that it is much faster to use a directed graph. There are several directed graph libraries available on NPM, including graph.js and directed-graph.
opt
- An options object
source
- A sourcedestination
- A destinationdepth
queue
- (Optional) Concurrency limit for recursive operations. Defaults to 100.recursion
- (Optional) Maximum path recursion. Defaults to 5.err
, boolean areConnected
) cb
- A function to be executed after the check is completedExample
connections.areConnected(
{
source: 'A',
destination: 'D',
depth: {
queue: 100,
recursion: 10
}
}, function(err, areConnected) {
if (err) { throw err; }
console.log(areConnected); //true
}
);
err
))If the connection source / destination CSV data is loaded via URL or file system path, the API methods cannot be called until this event is emitted
Example
var path = require('path'),
connections = Connections({source: path.join(__dirname, 'test.csv')});
connections.events.on('ready', function(err) {
if (err) { throw err; }
connections.areConnected(
{
source: 'A',
destination: 'D',
depth: {
queue: 100,
recursion: 10
}
}, function(err, areConnected) {
if (err) { throw err; }
console.log(areConnected); //true
}
);
});
npm install connection-paths --save
FAQs
Determine if two things are connected (e.g. network nodes) and generate a list of possible paths
We found that connection-paths 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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.