Skip to content

Commit

Permalink
example code 📝
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
derhuerst committed Jun 24, 2023
1 parent 17d0ba4 commit ea2feee
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

const assert = require('assert')
const flix = require('.')

const find = (name, stream) => {
return new Promise((resolve, reject) => {
stream.once('error', reject)
stream.on('data', (item) => {
if (item.name === name) resolve(item)
})
stream.once('end', () => resolve(null))
})
}

;(async () => {
const berlin = await find('Berlin', flix.regions.all())
assert.ok(berlin, 'Berlin not found')
const hamburg = await find('Hamburg', flix.regions.all())
assert.ok(hamburg, 'Hamburg not found')
const berlinAlexanderplatz = await find('Berlin Alexanderplatz', flix.stations.all())
assert.ok(berlinAlexanderplatz, 'Berlin Alexanderplatz not found')

const [journey] = await flix.journeys(berlin, hamburg, {
departureAfter: new Date('2020-06-01T08:00+02:00'),
results: 1,
})
console.error(journey)

const [depAtAlexanderplatz] = await flix.departures(berlinAlexanderplatz)
console.error(depAtAlexanderplatz)
})()
.catch((err) => {
console.error(err)
process.exit(1)
})

0 comments on commit ea2feee

Please sign in to comment.