npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

connection-paths

v1.0.5

Published

Determine if two things are connected (e.g. network nodes) and generate a list of possible paths

Readme

node-connection-paths

Description

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.

API

Connections(opt)

Instantiate Connections

  • object opt - An options object
    • string | array{array{string}} source - An array of arrays of two strings or URL or file system path to a CSV file that maps sources to destinations
    • boolean hasHeader - (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']]
        }
    );

connections.getDestinations(source, cb)

Get the destinations of a source

  • string opt - A source
  • function(null | object err, array destinations) cb - A function to be executed after the destinations are collected

Example

connections.getDestinations('A', function(err, destinations) {
    if (err){ throw err; }
    console.log(destinations); //[ 'B', 'C' ]
});

connections.getPaths(opt, cb)

Generate possible paths between a source and destination

  • object opt - An options object
    • string source - A source
    • string destination - A destination
    • boolean reverse - Whether or not a node is allowed to connect to the previous node. Defaults to false.
    • boolean revisit - Whether or not a node is allowed to connect to any previous nodes. Defaults to false.
    • string 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".
    • number max - (Optional) The maximum number of paths to generate. Defaults to 100.
    • object depth
      • number queue - (Optional) Concurrency limit for recursive operations. Defaults to 500.
      • number recursion - (Optional) Maximum path recursion. Defaults to 5.
  • function(null | object err, array{string} | array{array{string}} paths) cb - A function to be executed after the paths are generated

Example

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' ]
    }
);

connections.areConnected(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.

  • object opt - An options object
    • string source - A source
    • string destination - A destination
    • object depth
      • number queue - (Optional) Concurrency limit for recursive operations. Defaults to 100.
      • number recursion - (Optional) Maximum path recursion. Defaults to 5.
  • function(null | object err, boolean areConnected) cb - A function to be executed after the check is completed

Example

connections.areConnected(
    {
        source: 'A',
        destination: 'D',
        depth: {
            queue: 100,
            recursion: 10
        }
    }, function(err, areConnected) {
        if (err) { throw err; }
        console.log(areConnected); //true
    }
);

Events

connections.events.on('ready', function(null | object 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
        }
    );
});

Installation

Npm

npm install connection-paths --save