Utility to collect departures, using any HAFAS client.
npm install hafas-collect-departures-at
import {createVbbHafas} from 'vbb-hafas'
import {createCollectDeps} from 'hafas-collect-departures-at'
const fooStation = '900000100001'
const hafas = createVbbHafas('my-awesome-program')
const collectDeps = createCollectDeps(hafas.departures, {
departuresOpts: {
remarks: true,
products: {tram: false},
},
})
const depsAtFoo = collectDeps(fooStation, Date.now())
let iterations = 0
for await (const deps of depsAtFoo) {
if (++iterations > 2) break
console.log(deps)
}
If you don't like to use the async iteration syntax, there's a helper that works like a regular while
loop:
import {createCollectDepsWhile} from 'hafas-collect-departures-at/while.js'
const collectWhile = createCollectDepsWhile(vbb.departures)
const shouldPick = (dep, i) => i < 10
const deps = await collectWhile(fooStation, Date.now(), shouldPick)
console.log(deps)
collectWhile()
returns a Promise that will resolve with an array of 10 items.
hafas-find-alternative-legs
– Given ahafas-client
journey, get alternatives for each leg from HAFAS.
If you have a question or have difficulties using hafas-collect-departures-at
, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.