Socket
Socket
Sign inDemoInstall

create-paths

Package Overview
Dependencies
6
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    create-paths

Create a graph like structure with nodes and edges and calculate the duration between positions along the graph


Version published
Weekly downloads
6
decreased by-25%
Maintainers
1
Install size
151 kB
Created
Weekly downloads
 

Readme

Source

create-paths

experimental

Create a graph like structure with nodes and edges and calculate the duration between positions along the graph.

Example

var createPaths = require('create-paths');

var traverse = createPaths( [
    ['a', 'b', 1],
    ['a', 'c', 0.5],
    ['c', 'b', 0.25]
]);

// { duration: 0.75, path: [ 'a', 'c', 'b' ] }
console.log(traverse('a', 'b')); 

// { duration: 0.85, path: [ 'a', 'c', 'b' ] }
console.log(traverse({ from: 'a', to: 'b', location: 0.1 }, 'b')); 

Usage

NPM

var traverse = require('create-paths')(map);

When this module is passed a map it will return a function which can be used to traverse the network of underlying nodes to find the path from one location to another.

map should be an a two dimensional array. Each element of that array should describe a segment of a path.

So in the example:

[
    ['a', 'b', 1],
    ['a', 'c', 0.5],
    ['c', 'b', 0.25]
]

['a', 'b', 1] describes that you can go from 'a' to 'b' in 1.

var info = traverse(from, to);

The returned traverse function can be used to find the path and duration between two locations.

from can be a simple string which correlates to the original map passed in. Or i can describe a location between two locations using the following notations:

{ from: 'a', to: b: 'b', location: 0.1 }

Which states we're between 'a' and 'b' at 0.1.

to must always be a string.

info will be null if a path cannot be found between two locations. If path can be found it will be in the form:

{
    duration: 0.5,
    path: [ 'a', 'b', 'c' ]
}

Where duration is how the total distance/duration defined by the original map passed in. path is the name of the nodes that will be visited.

License

MIT, see LICENSE.md for details.

Keywords

FAQs

Last updated on 29 Jul 2015

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc