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

lvb

v1.0.6

Published

Inofficial LVB (Leipziger Verkehrsbetriebe) API client.

Downloads

40

Readme

lvb

Client for the LVB (Leipziger Verkehrsbetriebe) API. Inofficial, please ask LVB for permission before using this module in production. Actually, there should be no need for projects like this since municipal public transportation endpoints should be open to the public. It's 2021.

npm version license

Installation

npm install --save lvb

Usage

This package mostly returns data in the Friendly Public Transport Format:

stations(query, [opt])

Using lvb.stations, you can query stations operated bei LVB.

const stations = require('lvb').stations

stations('Nationalbibliothek').then(console.log)

Returns a Promise that will resolve in an array of stations in the Friendly Public Transport Format which looks as follows:


[
    {
        "id": "11558",
        "type": "station",
        "name": "Leipzig, Deutsche Nationalbibliothek",
        "coordinates": {
            "longitude": 12.396131411662,
            "latitude": 51.323542325868
        }
    }
    // …
]

defaults, partially overridden by the opt parameter, looks as follows:

const defaults = {
    limit: 5 // Maximum number of returned results. CAUTION: Because of something unlucky that happens to station ids in the API, a `stations` request will spawn (number of results + 1) requests. Keep this in mind when increasing this threshold.
}

departures(station, date = Date.now())

Using lvb.departures, you can get departures at a given station for a specific date and time.

const departures = require('lvb').departures

const Nationalbibliothek = '11558'

departures(Nationalbibliothek, new Date())

Returns a Promise that will resolve in a list of objects (one object per direction per line) like this:

[
    {
        "line": {
            "id": "16",
            "name": "Str   16", // yeah, that really looks like this :/
            "class": "StN",
            "operator": "LVB",
            "direction": "Lößnig über Connewitz, Kreuz"
        },
        "timetable": [
            {
                "departure": "2017-10-09T16:09:00.000Z", // JS Date() object
                "departureDelay": 0
            },
            {
                "departure": "2017-10-09T16:19:00.000Z", // JS Date() object
                "departureDelay": 0
            },
            {
                "departure": "2017-10-09T16:29:00.000Z", // JS Date() object
                "departureDelay": 0
            },
            {
                "departure": "2017-10-09T16:39:00.000Z", // JS Date() object
                "departureDelay": 0
            },
            {
                "departure": "2017-10-09T16:51:00.000Z", // JS Date() object
                "departureDelay": 0
            }
        ]
    }
    // …
]

journeys(origin, destination, date = Date.now(), [opt])

Using lvb.journeys, you can get directions and prices for routes from A to B.

const journeys = require('lvb').journeys

journeys(origin, destination, date = Date.now(), opt = defaults)

const Nationalbibliothek = '11558'
const Messe = '10818'
const date = new Date()

journeys(Nationalbibliothek, Messe, date)
.then(console.log)
.catch(console.error)

Returns a Promise that will resolve with an array of journeys in the Friendly Public Transport Format which looks as follows. Note that the legs are not (fully) spec-compatible, as the schedule is missing (see the line and route keys instead).

[
    {
        "type": "journey",
        "id": "Leipzig, Deutsche Nationalbibliothek@20171009173100@Leipzig, Wilhelm-Leuschner-Platz@20171009173900@SEV16@BUN-Leipzig, Wilhelm-Leuschner-Platz@20171009174200@Leipzig, Messegelände@20171009180800@16@STN",
        "legs": [
            {
                "origin": {
                    "type": "station",
                    "name": "Leipzig, Deutsche Nationalbibliothek",
                    "id": 11558,
                    "coordinates": {
                        "longitude": 12.395702,
                        "latitude": 51.32357
                    }
                },
                "destination": {
                    "type": "station",
                    "name": "Leipzig, Wilhelm-Leuschner-Platz",
                    "id": 12992,
                    "coordinates": {
                        "longitude": 12.375872,
                        "latitude": 51.335876
                    }
                },
                "line": {
                    "id": "SEV16",
                    "class": "BUN",
                    "direction": "Wilhelm-Leuschner-Platz",
                    "operator": "Leipziger Verkehrsbetriebe",
                    "color": "#017C46"
                },
                "route": [
                    {
                        "type": "station",
                        "id": 11558,
                        "name": "Leipzig, Deutsche Nationalbibliothek",
                        "coordinates": {
                            "longitude": 12.395702,
                            "latitude": 51.32357
                        }
                    },
                    {
                        "type": "station",
                        "id": 11557,
                        "name": "Leipzig, Johannisallee",
                        "coordinates": {
                            "longitude": 12.388807,
                            "latitude": 51.327309
                        }
                    }
                    // …
                ],
                "departure": "2017-10-09T15:31:00.000Z", // JS Date() object
                "departureDelay": 0,
                "arrival": "2017-10-09T15:39:00.000Z", // JS Date() object
                "arrivalDelay": 0,
                "departurePlatform": null,
                "arrivalPlatform": null
            },
            {
                "origin": {
                    "type": "station",
                    "name": "Leipzig, Wilhelm-Leuschner-Platz",
                    "id": 12992,
                    "coordinates": {
                        "longitude": 12.375872,
                        "latitude": 51.335876
                    }
                },
                "destination": {
                    "type": "station",
                    "name": "Leipzig, Messegelände",
                    "id": 10818,
                    "coordinates": {
                        "longitude": 12.396583,
                        "latitude": 51.396724
                    }
                },
                "line": {
                    "id": "16",
                    "class": "STN",
                    "direction": "Messegelände",
                    "operator": "Leipziger Verkehrsbetriebe",
                    "color": "#017C46"
                },
                "route": [
                    {
                        "type": "station",
                        "id": 12992,
                        "name": "Leipzig, Wilhelm-Leuschner-Platz",
                        "coordinates": {
                            "longitude": 12.375872,
                            "latitude": 51.335876
                        }
                    },
                    {
                        "type": "station",
                        "id": 13002,
                        "name": "Leipzig, Augustusplatz",
                        "coordinates": {
                            "longitude": 12.382012,
                            "latitude": 51.338905
                        }
                    }
                    // …
                ],
                "departure": "2017-10-09T15:42:00.000Z", // JS Date() object
                "departureDelay": 0,
                "arrival": "2017-10-09T16:08:00.000Z", // JS Date() object
                "arrivalDelay": 0,
                "departurePlatform": null,
                "arrivalPlatform": null
            }
        ],
        "price": {
            "model": "Einzelfahrkarte",
            "amount": 2.6,
            "currency": "EUR",
            "fares": [
                {
                    "type": "fare",
                    "model": "Einzelfahrkarte",
                    "amount": 2.6,
                    "currency": "EUR"
                },
                {
                    "type": "fare",
                    "model": "Einzelfahrkarte Kind",
                    "amount": 1.2,
                    "currency": "EUR"
                },
                {
                    "type": "fare",
                    "model": "4-Fahrten-Karte",
                    "amount": 10.4,
                    "currency": "EUR"
                }
                // …
            ]
        },
        "zones": {
            "departure": "110",
            "arrival": "110",
            "list": "110"
        }
    }
    // …
]

defaults, partially overridden by the opt parameter, looks like this:

const defaults = {
    via: null // station id
}

See also

  • FPTF - "Friendly public transport format"
  • FPTF-modules - modules that also use FPTF

Contributing

If you found a bug or want to propose a feature, feel free to visit the issues page.