hafas-discover-stations

Pass in a HAFAS client, discover stations by querying departures.

Usage no npm install needed!

<script type="module">
  import hafasDiscoverStations from 'https://cdn.skypack.dev/hafas-discover-stations';
</script>

README

hafas-discover-stations

Pass in a HAFAS client, discover stops/stations by querying departures. It tries to find all stops/stations that all trains known by the endpoint stop at.

npm version build status ISC-licensed support me via GitHub Sponsors chat with me on Twitter

Installing

npm install hafas-discover-stations

Usage

const createWalk = require('hafas-discover-stations')
const createHafas = require('hafas-client')
const dbProfile = require('hafas-client/p/db')

const hafas = createHafas(dbProfile, 'my-awesome-program')
const walk = createWalk(hafas)

const berlinFriedrichstr = '8011306' // where to start
walk(berlinFriedrichstr)
.on('data', console.log)
.on('error', console.error)

walk() returns a readable stream in object mode. It emits the following events:

  • data: a new stop/station that has been discovered
  • stats: an object with the following keys:
    • stopsAndStations: the number of stops/stations discovered
    • edges: the number of edges discovered
    • totalReqs: the number of requests sent
    • avgReqDuration: the average duration of the last 30 requests
    • queuedReqs: the number of queued requests
  • edge: a connection between two stops/stations, with the following keys:

API

walk(stationId, [opt])

opt may have the following keys. It will be passed into queue().

  • concurrency: number of requests run in parallel – default: 2
  • timeout: timeout for a single job in milliseconds – default: 10000
  • parseStationId: an optional function to process station IDs – default: id => id
  • stationLines: Query lines of stops/stations? – default: false

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.