@roehrt/baahn
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

Baahn! 🚂

baahn lets you find special connections saving money when travelling with Deutsche Bahn (DB). It's using hafas-client (huge thanks!) under the hood for fetching information about journeys.

Suppose you plan to travel from Berlin Hbf to Magdeburg Hbf. This package finds a longer journey containing the actual journey from Berlin to Magdeburg but which is cheaper (yep, the DB price system is weeeird).

The output of the baahn web app:

baahn web app in action

Installation

npm i @roehrt/baahn

Example

const { findJourneys } = require('@roehrt/baahn');
findJourneys('8011160', '8010224').then((data) => {
  console.log(require('util').inspect(data, {depth: null, colors: true}))
});

For finding the station ids hafas-client is recommended. For everyday use consider using the baahn-cli package.

More information on how to use findJourneys can be found in the hafas-client docs: journeys and findJourneys have the same signature and nearly the same return type and can therefore be used interchangeably. The only additional property that findJourneys return is an optional object trick storing how the price saving was achieved.

interface BaahnJourney extends Journey {
  trick?: {
    prepend: Leg[],
    append: Leg[],
    oldPrice: number,
  }
}
  • oldPrice stores the unoptimized price.
  • prepend stores all legs that need to be prepended to the original journey.
  • append stores all legs that need to be appended to the original journey.

Known Problems

baahn uses a graph of long-distance train stations, so it won't find many tricks if the origin or destination is a non-long-distance station. In fact if both - origin and destination - are non-long-distance stations the search will never respond with an improved price since the stations are missing in the adjacency list (stationGraph.json).

The graph may be merged with this edge list in the future.

For further information visit the rather spartan FAQ (German).

See Also

baahn-cli - a simple cli wrapper for this module.

Package Sidebar

Install

npm i @roehrt/baahn

Weekly Downloads

0

Version

1.1.3

License

ISC

Unpacked Size

47.2 kB

Total Files

6

Last publish

Collaborators

  • roehrt