npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mav-prices

v0.4.0

Published

Find the cheapest fares using the MAV API.

Downloads

26

Readme

mav-prices

JavaScript module for finding railway connections prices using the Magyar Államvasutak (MÁV, Hungarian State Railways) API. Inofficial, using an endpoint by Magyar Államvasutak. Please ask them for permission before using this module in production.

Currently only supports international railway connections from/to Hungary.

npm version ISC-licensed

Installation

npm install mav-prices

Usage

queryPrices() returns a Promise that will resolve with a list of offers.

import { queryPrices } from 'mav-prices';

queryPrices(from, to, [date], [opt]).then(…)

from and to must be MAV station IDs like "008099970".

date must be a Date object; if empty, the current datetime will be used.

With opt, you can override the default options, which look like this:

{
  class: 2, // 1 or 2 for first or second class
  seatReservation: false,
  directConnection: false,
  duration: 480, // search for connections within n minutes after departure date (default: undefined; note: 1 API request per 480 minutes will be sent)
  longerTransferTime: false, // >=10 minutes transfer time guaranteed
  isArrivalDate: false, // specify whether date parameter is arrival or departure date; ignored if duration is set
  intermediateStations: [ // 0-3 objects for intermediate stations (sample object is not set as default)
    {
      stationCode: "008062648", // station ID
      durationOfStay: 5 // in minutes (max: 59 (officially), but more seems to work as well);
                        // set to 0 if train should at least pass through station
    }
  ],
  travellers: [ // one or more objects; up to six people and six dogs
    {
      type: '8', // passengerType
      discounts: [], // discount IDs
    }
  ],
}

The following traveller and discount types are available for international journeys:

{
  passengerTypes: [
    { '0': 'Child (0-4 years)' },
    { '1': 'Child (4-6 years)' },
    { '2': 'Child (6-12 years)' },
    { '3': 'Child (12-14 years)' },
    { '4': 'Youth (14-15 years)' },
    { '5': 'Youth (15-16 years)' },
    { '6': 'Teenager (16-18 years)' },
    { '7': 'Young adult (18-26 years)' },
    { '8': 'Adult (26+ years)' },
    { '9': 'Dog' },
    { '10': 'Bicylce' },
  ],
  discounts: [
    { '1': 'BahnCard 25' },
    { '3': 'BahnCard 50' },
    { '5': 'BahnCard 100' },
    { '8': 'Vorteilscard' },
    { '9': 'Generalabonnement' },
    { '10': 'Halbtaxabonnement' },
    { '11': 'Klimaticket' },
  ],
}

Response

The result will be a list of Friendly Public Transport Format journey objects.

With from = '008099970', to = '005501362' and date = new Date('2023-01-09T09:30:00.000Z'), the result looked like this:

[
  {
    type: 'journey',
    id: 181926962,
    legs: [
      {
        mode: 'train',
        origin: { type: 'station', id: '008001071', name: 'Hamburg Hbf' },
        destination: { type: 'station', id: '008022534', name: 'Würzburg Hbf' },
        departure: '2023-01-09T12:01:00+01:00',
        departureDelay: 0,
        departurePlatform: undefined,
        arrival: '2023-01-09T15:28:00+01:00',
        arrivalDelay: 0,
        arrivalPlatform: undefined,
        line: {
          type: 'line',
          id: '6528402',
          name: 'ICE 789',
          mode: 'train',
          product: 'ICE',
        },
        schedule: '683163',
      },
      {
        mode: 'train',
        origin: { type: 'station', id: '008022534', name: 'Würzburg Hbf' },
        destination: { type: 'station', id: '008101073', name: 'Linz Hbf' },
        departure: '2023-01-09T15:35:00+01:00',
        departureDelay: 0,
        departurePlatform: undefined,
        arrival: '2023-01-09T19:26:00+01:00',
        arrivalDelay: 0,
        arrivalPlatform: undefined,
        line: {
          type: 'line',
          id: '6525223',
          name: 'ICE 29',
          mode: 'train',
          product: 'ICE',
        },
        schedule: '690816',
      },
      {
        mode: 'train',
        origin: { type: 'station', id: '008101073', name: 'Linz Hbf' },
        destination: { type: 'station', id: '005501362', name: 'Hegyeshalom' },
        departure: '2023-01-09T20:17:00+01:00',
        departureDelay: 0,
        departurePlatform: undefined,
        arrival: '2023-01-09T22:25:00+01:00',
        arrivalDelay: 0,
        arrivalPlatform: undefined,
        line: {
          type: 'line',
          id: '6493390',
          name: 'RJX 261',
          mode: 'train',
          product: 'RJX',
        },
        schedule: '658654',
      },
    ],
    price: { amount: 115, currency: 'EUR', name: 'START Europa DE' },
  },
  // ...
];

Similar Projects

Contributing

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