hafas-collect-departures-at

4.0.1 • Public • Published

hafas-collect-departures-at

Utility to collect departures, using any HAFAS client.

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

Installing

npm install hafas-collect-departures-at

Usage

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)
}

while helper

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.

Related

Contributing

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.

Package Sidebar

Install

npm i hafas-collect-departures-at

Weekly Downloads

10

Version

4.0.1

License

ISC

Unpacked Size

6.42 kB

Total Files

5

Last publish

Collaborators

  • derhuerst