­čÜŐ Query Dresden's public transport system for current bus- and tramstop data in node
Clone or download
Fetching latest commitÔÇŽ
Cannot retrieve the latest commit at this time.

README.md

dvbjs

travis-ci Coverage Status npmversion Downloads

NPM

This is an unofficial node module, giving you a few options to query Dresden's public transport system for current bus- and tramstop data.

Want something like this for another language, look no further ­čÖé

Getting Started

Install the module using npm

$ yarn install dvbjs

and require it in your project

import * as dvb from "dvbjs";

HTTP request are handled by axios that supports all modern browsers. See react-example for a browser departure monitor example.

Example Usage

Find stops by name

const dvb = require("dvbjs");

dvb.findStop("zellesch").then(function (data) {
    console.log(JSON.stringify(data, null, 4));
})
[
    {
        "city": "Dresden",
        "coords": [
            13.745858712566005,
            51.02836082515807
        ],
        "name": "Zellescher Weg",
        "id": "33000312",
        "type": "Stop"
    }
]

Monitor a single stop

const dvb = require("dvbjs");

const stopID = "33000037"; // Postplatz
var timeOffset = 5;
var numResults = 2;

dvb.monitor(stopID, timeOffset, numResults).then(function (data) {
    console.log(JSON.stringify(data, null, 4));
})
[
    {
        "arrivalTime": "2018-07-29T22:00:00.000Z",
        "scheduledTime": "2018-07-29T22:00:00.000Z",
        "id": "76185070",
        "line": "EV4",
        "direction": "Postplatz",
        "platform": {
            "name": "2",
            "type": "Platform"
        },
        "arrivalTimeRelative": 8,
        "scheduledTimeRelative": 8,
        "delayTime": 0,
        "state": "InTime",
        "mode": {
            "title": "Bus",
            "name": "CityBus",
            "icon_url": "https://www.dvb.de/assets/img/trans-icon/transport-bus.svg"
        },
        "diva": {
            "number": 27004,
            "network": "voe"
        }
    },
    {
        "arrivalTime": "2018-07-29T22:00:00.000Z",
        "scheduledTime": "2018-07-29T22:00:00.000Z",
        "id": "76185196",
        "line": "EV4",
        "direction": "Tolkewitz",
        "platform": {
            "name": "1",
            "type": "Platform"
        },
        "arrivalTimeRelative": 8,
        "scheduledTimeRelative": 8,
        "delayTime": 0,
        "state": "InTime",
        "mode": {
            "title": "Bus",
            "name": "CityBus",
            "icon_url": "https://www.dvb.de/assets/img/trans-icon/transport-bus.svg"
        },
        "diva": {
            "number": 27004,
            "network": "voe"
        }
    }
]

Find routes

const dvb = require("dvbjs");

const origin = "33000742"; // Helmholtzstra├če
const destination = "33000037"; // Postplatz
var startTime = new Date();

dvb.route(origin, destination, startTime).then(function (data) {
    console.log(JSON.stringify(data, null, 4));
})
{
    "origin": {
        "name": "Helmholtzstra├če",
        "city": "Dresden",
        "coords": [
            13.725468471273134,
            51.0255443264448
        ]
    },
    "destination": {
        "name": "Postplatz",
        "city": "Dresden",
        "coords": [
            13.732548433606716,
            51.049882551705295
        ]
    },
    "trips": [
        {
            "nodes": [
                {
                    "stops": [
                        {
                            "name": "Helmholtzstra├če",
                            "city": "Dresden",
                            "type": "Stop",
                            "coords": [
                                13.725468471273134,
                                51.0255443264448
                            ],
                            "arrival": "2018-07-29T20:53:00.000Z",
                            "departure": "2018-07-29T20:53:00.000Z"
                        },
                        {
                            "name": "Mommsenstra├če",
                            "city": "Dresden",
                            "type": "Stop",
                            "platform": {
                                "name": "1",
                                "type": "Platform"
                            },
                            "coords": [
                                13.731503998392713,
                                51.02761256018972
                            ],
                            "arrival": "2018-07-29T21:02:00.000Z",
                            "departure": "2018-07-29T21:02:00.000Z"
                        }
                    ],
                    "departure": {
                        "name": "Helmholtzstra├če",
                        "city": "Dresden",
                        "time": "2018-07-29T20:53:00.000Z",
                        "coords": [
                            13.725468471273134,
                            51.0255443264448
                        ],
                        "type": "Stop"
                    },
                    "arrival": {
                        "name": "Mommsenstra├če",
                        "city": "Dresden",
                        "platform": {
                            "name": "1",
                            "type": "Platform"
                        },
                        "time": "2018-07-29T21:02:00.000Z",
                        "coords": [
                            13.731503998392713,
                            51.02761256018972
                        ],
                        "type": "Stop"
                    },
                    "mode": {
                        "title": "Fussweg",
                        "name": "Footpath",
                        "icon_url": "https://m.dvb.de/img/walk.svg"
                    },
                    "line": "Fussweg",
                    "direction": "",
                    "duration": 1,
                    "path": [
                        [
                            13.725468471273134,
                            51.0255443264448
                        ],
                        {...}
                        [
                            13.731503998392713,
                            51.02761256018972
                        ]
                    ]
                },
                {
                    "stops": [
                        {
                            "name": "Mommsenstra├če",
                            "city": "Dresden",
                            "type": "Stop",
                            "platform": {
                                "name": "1",
                                "type": "Platform"
                            },
                            "coords": [
                                13.731503998392713,
                                51.02761256018972
                            ],
                            "arrival": "2018-07-29T21:02:00.000Z",
                            "departure": "2018-07-29T21:02:00.000Z"
                        },
                        {...}
                        {
                            "name": "Postplatz",
                            "city": "Dresden",
                            "type": "Stop",
                            "platform": {
                                "name": "8",
                                "type": "Platform"
                            },
                            "coords": [
                                13.732548433606716,
                                51.049882551705295
                            ],
                            "arrival": "2018-07-29T21:11:00.000Z",
                            "departure": "2018-07-29T21:11:00.000Z"
                        }
                    ],
                    "departure": {
                        "name": "Mommsenstra├če",
                        "city": "Dresden",
                        "platform": {
                            "name": "1",
                            "type": "Platform"
                        },
                        "time": "2018-07-29T21:02:00.000Z",
                        "coords": [
                            13.731503998392713,
                            51.02761256018972
                        ],
                        "type": "Stop"
                    },
                    "arrival": {
                        "name": "Postplatz",
                        "city": "Dresden",
                        "platform": {
                            "name": "8",
                            "type": "Platform"
                        },
                        "time": "2018-07-29T21:11:00.000Z",
                        "coords": [
                            13.732548433606716,
                            51.049882551705295
                        ],
                        "type": "Stop"
                    },
                    "mode": {
                        "title": "Bus",
                        "name": "CityBus",
                        "icon_url": "https://www.dvb.de/assets/img/trans-icon/transport-bus.svg"
                    },
                    "line": "360",
                    "direction": "Dresden Postplatz",
                    "diva": {
                        "number": 23360,
                        "network": "voe"
                    },
                    "duration": 1,
                    "path": [
                        [
                            13.73146092123584,
                            51.02760420891756
                        ],
                        {...}
                        [
                            13.732534179344674,
                            51.0498827630612
                        ]
                    ]
                }
            ],
            "departure": {
                "name": "Helmholtzstra├če",
                "city": "Dresden",
                "time": "2018-07-29T20:53:00.000Z",
                "coords": [
                    13.725468471273134,
                    51.0255443264448
                ],
                "type": "Stop"
            },
            "arrival": {
                "name": "Postplatz",
                "city": "Dresden",
                "platform": {
                    "name": "8",
                    "type": "Platform"
                },
                "time": "2018-07-29T21:11:00.000Z",
                "coords": [
                    13.732548433606716,
                    51.049882551705295
                ],
                "type": "Stop"
            },
            "duration": 1,
            "interchanges": 0
        },
        {...}
    ]
}

API Documentation

Table of contents

index.ts

Functions

coords

Find the coordinates for a given POI id.

function coords(id: string): Promise<number[] | undefined>;

Parameters

Name Type Description
id string the POI ID

Return type

Promise<number[] | undefined>


findAddress

Lookup address and nearby stops by coordinate.

function findAddress(lng: number, lat: number): Promise<IAddress | undefined>;

Parameters

Name Type Description
lng number longitude of the coordinate
lat number latitude of the coordinate

Return type

Promise<IAddress | undefined>


findPOI

Search for POI in the network of the DVB.

function findPOI(searchString: string): Promise<IPoint[]>;

Parameters

Name Type Description
searchString string the name of the stop

Return type

Promise<IPoint[]>


findStop

Search for a single stop in the network of the DVB.

function findStop(searchString: string): Promise<IPoint[]>;

Parameters

Name Type Description
searchString string the name of the stop

Return type

Promise<IPoint[]>


lines

get a list of availible tram/bus lines for a stop.

function lines(stopID: string): Promise<ILine[]>;

Parameters

Name Type Description
stopID string the stop ID

Return type

Promise<ILine[]>


monitor

Monitor a single stop to see every bus or tram leaving this stop after the specified time offset.

function monitor(stopID: string, offset: number = 0, amount: number = 0): Promise<IMonitor[]>;

Parameters

Name Type Default value Description
stopID string ID of the stop
offset number 0 how many minutes in the future, 0 for now
amount number 0 number of results

Return type

Promise<IMonitor[]>


pins

Search for different kinds of POIs inside a given bounding box.

function pins(swlng: number, swlat: number, nelng: number, nelat: number, pinTypes: PIN_TYPE[] = [PIN_TYPE.stop]): Promise<IPin[]>;

Parameters

Name Type Default value Description
swlng number the longitude of the south west coordinate
swlat number the latitude of the south west coordinate
nelng number the longitude of the north east coordinate
nelat number the latitude of the north east coordinate
pinTypes PIN_TYPE[] [PIN_TYPE.stop] array of pin types

Return type

Promise<IPin[]>


route

Query the server for possible routes from one stop to another.

function route(originID: string, destinationID: string, time: Date = new Date(), isArrivalTime: boolean = true): Promise<IRoute>;

Parameters

Name Type Default value Description
originID string the id of the origin stop
destinationID string the id of the destination stop
time Date new Date() starting at what time
isArrivalTime boolean true is time the arrival time

Return type

Promise<IRoute>

Interfaces

IDiva
interface IDiva {
    number: number;
    network?: string | undefined;
}

Properties

Name Type Optional
number number false
network string | undefined true

IPlatform
interface IPlatform {
    name: string;
    type: string;
}

Properties

Name Type Optional
name string false
type string false

IPin
  • The id for PIN_TYPE.platform is always an empty string.
  • PIN_TYPE.platform conatins platform_nr.
  • PIN_TYPE.stop contains connections.
  • PIN_TYPE.parkandride contains info.
interface IPin {
    id: string;
    type: PIN_TYPE;
    name: string;
    coords: Array<number>;
    platform_nr?: string | undefined;
    connections?: IConnection[];
    info?: string | undefined;
}

Properties

Name Type Optional
id string false
type PIN_TYPE false
name string false
coords Array false
platform_nr string | undefined true
connections IConnection[] true
info string | undefined true

IConnection
interface IConnection {
    line: string;
    mode: IMode;
}

Properties

Name Type Optional
line string false
mode IMode false

IMode
interface IMode {
    title: string;
    name: string;
    icon_url?: string | undefined;
}

Properties

Name Type Optional
title string false
name string false
icon_url string | undefined true

IPoint
interface IPoint {
    city: string;
    name: string;
    id: string;
    coords: Array<number>;
    type: POI_TYPE;
}

Properties

Name Type Optional
city string false
name string false
id string false
coords Array false
type POI_TYPE false

IAddress
interface IAddress extends IPoint {
    stops: IPoint[];
}

Extends

IPoint

Properties

Name Type Optional
stops IPoint[] false

ILine
interface ILine {
    name: string;
    mode: IMode;
    diva?: IDiva | undefined;
    directions: string[];
}

Properties

Name Type Optional
name string false
mode IMode false
diva IDiva | undefined true
directions string[] false

IMonitor
interface IMonitor {
    arrivalTime: Date;
    scheduledTime: Date;
    id: string;
    line: string;
    direction: string;
    platform?: IPlatform | undefined;
    arrivalTimeRelative: number;
    scheduledTimeRelative: number;
    delayTime: number;
    state: string;
    mode: IMode;
    diva?: IDiva | undefined;
}

Properties

Name Type Optional
arrivalTime Date false
scheduledTime Date false
id string false
line string false
direction string false
platform IPlatform | undefined true
arrivalTimeRelative number false
scheduledTimeRelative number false
delayTime number false
state string false
mode IMode false
diva IDiva | undefined true

ILocation
interface ILocation {
    name: string;
    city: string;
    coords: Array<number>;
}

Properties

Name Type Optional
name string false
city string false
coords Array false

IStop
interface IStop extends ILocation {
    type: string;
    platform?: IPlatform | undefined;
    arrival: Date;
    departure: Date;
}

Extends

ILocation

Properties

Name Type Optional
type string false
platform IPlatform | undefined true
arrival Date false
departure Date false

IStopLocation
interface IStopLocation extends ILocation {
    platform?: IPlatform | undefined;
    time: Date;
    type: string;
}

Extends

ILocation

Properties

Name Type Optional
platform IPlatform | undefined true
time Date false
type string false

INode
interface INode {
    stops: IStop[];
    departure?: IStopLocation | undefined;
    arrival?: IStopLocation | undefined;
    mode: IMode;
    line: string;
    direction: string;
    diva?: IDiva | undefined;
    duration: number;
    path: Array<number>[];
}

Properties

Name Type Optional
stops IStop[] false
departure IStopLocation | undefined true
arrival IStopLocation | undefined true
mode IMode false
line string false
direction string false
diva IDiva | undefined true
duration number false
path Array[] false

ITrip
interface ITrip {
    departure?: IStopLocation | undefined;
    arrival?: IStopLocation | undefined;
    duration: number;
    interchanges: number;
    nodes: INode[];
}

Properties

Name Type Optional
departure IStopLocation | undefined true
arrival IStopLocation | undefined true
duration number false
interchanges number false
nodes INode[] false

IRoute
interface IRoute {
    origin?: ILocation | undefined;
    destination?: ILocation | undefined;
    trips: ITrip[];
}

Properties

Name Type Optional
origin ILocation | undefined true
destination ILocation | undefined true
trips ITrip[] false

Types

coord

WGS84 coordinates [lng, lat]

type coord = number[];

Type

number[]

Enums

POI_TYPE
enum POI_TYPE {
     Address = "Address",
     Coords = "Coords",
     POI = "POI",
     Stop = "Stop"
}

Members

Name Value
Address "Address"
Coords "Coords"
POI "POI"
Stop "Stop"

PIN_TYPE
enum PIN_TYPE {
     stop = "stop",
     platform = "platform",
     poi = "poi",
     rentabike = "rentabike",
     ticketmachine = "ticketmachine",
     carsharing = "carsharing",
     parkandride = "parkandride",
     unknown = "unknown"
}

Members

Name Value
stop "stop"
platform "platform"
poi "poi"
rentabike "rentabike"
ticketmachine "ticketmachine"
carsharing "carsharing"
parkandride "parkandride"
unknown "unknown"