3.0.2 • Published 5 years ago

ratakilometri v3.0.2

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

ratakilometri.js

Build Status npm license

Find the shortest route between two railway stations of Finland by using Dijkstra's algorithm. Station location data the library is using, is extracted from the PDF provided by Finnish Transport Agency and enriched with other information available freely on the Internet.

Install

With Yarn:

yarn add ratakilometri

Or with NPM:

npm i -S ratakilometri

Usage

const { getRoute, getDistance } = require('ratakilometri')()

Or this way:

import ratakm from 'ratakilometri'
const { getRoute, getDistance } = ratakm()

To find out distance or route:

const route = getRoute('HL', 'KV')
const distance = getDistance('TUS', 'HKI')

console.log(route, distance)

Options

As we pass parameters of getRoute almost directly to node-dijkstra, you can use options object of the library as a third parameter of getRoute.

  • trim: boolean, default false: If set to true, the result won't include the start and end stations.
  • reverse: boolean, default false: If set to true, the route array will be in reversed order, from the end to start
  • avoid: array, default []: Stations to be avoided

:information_source: Be aware algorithm really tries to find out the shortest path which isn't always the best path. For example, if you try to find out distance from Leppävaara (LPV) to Tikkurila (TKL) for the commercial passenger train, library would tell you to go thru Ilmala Rail Yard (ILR) which surely isn't the best route :wink:

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago