Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nahsh-hafas

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nahsh-hafas

JavaScript client for the NAH.SH HAFAS API.

  • 5.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

nahsh-hafas

Client for the Nahverkehrsverbund Schleswig-Holstein (NAH.SH) HAFAS API. It acts as a consistent and straightforward interface on top of a verbose API.

This project is actually a thin wrapper around hafas-client@5. Its docs document the API in general.

npm version dependency status dev dependency status license chat on gitter

Installing

npm install nahsh-hafas

API

Check the docs for hafas-client@2 as well as the NAH.SH-specific customisations.

Getting Started

const createClient = require('nahsh-hafas')

const client = createHafas('my-awesome-program-useragent')

As an example, we will search for a route from Flensburg to Kiel Hbf. To get the station ids, use locations(query, [opt]).

client.journeys('8000103', '8000199')
.then((journeys) => console.log(journeys[0]))
.catch(console.error)

The output will be a journey object in the Friendly Public Transport Format 1.0.1 format:

[ {
    type: "journey",
    legs: [
        {
            origin: {
                type: "station",
                id: "8000103",
                name: "Flensburg",
                location: {
                    type: "location",
                    latitude: 54.774043,
                    longitude: 9.436525
                },
                products: {
                    nationalExp: true,
                    national: true,
                    interregional: false,
                    regional: true,
                    suburban: false,
                    bus: false,
                    ferry: false,
                    subway: false,
                    tram: false,
                    onCall: false
                }
            },
            destination: {
                type: "station",
                id: "8000199",
                name: "Kiel Hbf",
                location: {
                    type: "location",
                    latitude: 54.314982,
                    longitude: 10.131976
                },
                products: {
                    nationalExp: true,
                    national: true,
                    interregional: false,
                    regional: true,
                    suburban: false,
                    bus: false,
                    ferry: false,
                    subway: false,
                    tram: false,
                    onCall: false
                }
            },
            departure: "2018-03-18T14:04:00.000+01:00",
            arrival: "2018-03-18T15:17:00.000+01:00",
            departureDelay: 0,
            arrivalDelay: 0,
            id: "1|36867|6|100|18032018",
            line: {
                type: "line",
                id: "re72",
                name: "RE72",
                public: true,
                class: 8,
                productCode: 3,
                operator: {
                    type: "operator",
                    id: "db-regio-ag-nord",
                    name: "DB Regio AG Nord"
                },
                product: "regional",
                mode: "train"
            },
            direction: "Kiel Hbf",
            departurePlatform: "4",
            arrivalPlatform: "6a"
        }
    ],
    origin: {
        type: "station",
        id: "8000103",
        name: "Flensburg",
        location: {
            type: "location",
            latitude: 54.774043,
            longitude: 9.436525
        },
        products: {
            nationalExp: true,
            national: true,
            interregional: false,
            regional: true,
            suburban: false,
            bus: false,
            ferry: false,
            subway: false,
            tram: false,
            onCall: false
        }
    },
    destination: {
        type: "station",
        id: "8000199",
        name: "Kiel Hbf",
        location: {
            type: "location",
            latitude: 54.314982,
            longitude: 10.131976
        },
        products: {
            nationalExp: true,
            national: true,
            interregional: false,
            regional: true,
            suburban: false,
            bus: false,
            ferry: false,
            subway: false,
            tram: false,
            onCall: false
        }
    },
    departure: "2018-03-18T14:04:00.000+01:00",
    arrival: "2018-03-18T15:17:00.000+01:00",
    tickets: [
        {
            name: "Normalpreis - Einzelkarte 2.Kl",
            tariff: "Normalpreis",
            variant: "Einzelkarte 2.Kl",
            amount: 18.7,
            currency: "EUR"
        },
        {
            name: "Normalpreis - Einzelkarte Kind 2.Kl",
            tariff: "Normalpreis",
            variant: "Einzelkarte Kind 2.Kl",
            amount: 11.25,
            currency: "EUR"
        }
        // …
    ]
} ]

Similar Projects

  • db-hafas – Client for the German Railways (DB).
  • oebb-hafas – Client for the Austrian Railways (ÖBB).
  • vbb-hafas – Client for the Berlin & Brandenburg public transport service (VBB).

Contributing

If you found a bug, want to propose a feature or feel the urge to complain about your life, feel free to visit the issues page.

Keywords

FAQs

Package last updated on 23 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc