6.2.0 • Published 5 months ago

dvbjs v6.2.0

Weekly downloads
11
License
MIT
Repository
github
Last release
5 months ago

dvbjs

travis-ci Coverage Status code style: prettier 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 or yarn

$ npm install dvbjs
or
$ yarn add dvbjs

and require it in your project

import * as dvb from "dvbjs";

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

Example Usage

Find stops by name

import * as dvb from "dvbjs"; // OR const dvb = require("dvbjs");

dvb.findStop("zellesch").then((data) => {
  console.dir({ data }, { depth: 7, maxArrayLength: 2 });
});
{
  data: [
    {
      city: 'Dresden',
      coords: [ 13.745859050200034, 51.0283698098441 ],
      name: 'Zellescher Weg',
      id: '33000312',
      type: 'Stop'
    },
    {
      city: 'Clausthal-Zellerfeld',
      coords: [ 10.347333308428196, 51.80899839555576 ],
      name: 'Eschenbacher Straße',
      id: '26005221',
      type: 'Stop'
    }
  ]
}

Monitor a single stop

import * as dvb from "dvbjs"; // OR const dvb = require("dvbjs");

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

dvb.monitor(stopID, timeOffset, numResults).then((data) => {
  console.dir(data, { depth: 7, maxArrayLength: 2 });
});
[
  {
    arrivalTime: 2020-07-31T00:40:00.000Z,
    scheduledTime: 2020-07-31T00:40:00.000Z,
    id: 'voe:21075: :R:j20',
    line: '75',
    direction: 'Postplatz',
    platform: { name: '8', type: 'Platform' },
    arrivalTimeRelative: 21,
    scheduledTimeRelative: 21,
    delayTime: 0,
    state: 'Unknown',
    mode: {
      title: 'Bus',
      name: 'CityBus',
      iconUrl: 'https://www.dvb.de/assets/img/trans-icon/transport-bus.svg'
    },
    diva: { number: 21075, network: 'voe' }
  },
  {
    arrivalTime: 2020-07-31T00:45:00.000Z,
    scheduledTime: 2020-07-31T00:45:00.000Z,
    id: 'voe:11002: :R:j20',
    line: '2',
    direction: 'Kleinzschachwitz',
    platform: { name: '1', type: 'Platform' },
    arrivalTimeRelative: 26,
    scheduledTimeRelative: 26,
    delayTime: 0,
    state: 'Unknown',
    mode: {
      title: 'Straßenbahn',
      name: 'Tram',
      iconUrl: 'https://www.dvb.de/assets/img/trans-icon/transport-tram.svg'
    },
    diva: { number: 11002, network: 'voe' }
  }
]

Find routes

import * as dvb from "dvbjs"; // OR const dvb = require("dvbjs");

const origin = "33000742"; // Helmholtzstraße
const destination = "33000037"; // Postplatz
const startTime = new Date();
const isArrivalTime = false;

dvb.route(origin, destination, startTime, isArrivalTime).then((data) => {
  console.dir(data, { depth: 7, maxArrayLength: 2 });
});
{
  origin: {
    id: '33000742',
    name: 'Helmholtzstraße',
    city: 'Dresden',
    coords: [ 13.725468471273134, 51.0255443264448 ]
  },
  destination: {
    id: '33000037',
    name: 'Postplatz',
    city: 'Dresden',
    coords: [ 13.733543221907427, 51.05055101347277 ]
  },
  trips: [
    {
      nodes: [
        {
          stops: [
            {
              id: '33000742',
              name: 'Helmholtzstraße',
              city: 'Dresden',
              type: 'Stop',
              platform: undefined,
              coords: [ 13.725468471273134, 51.0255443264448 ],
              arrival: 2020-07-31T01:18:00.000Z,
              departure: 2020-07-31T01:18:00.000Z
            },
            {
              id: '33000135',
              name: 'Plauen Nöthnitzer Straße',
              city: 'Dresden',
              type: 'Stop',
              platform: { name: '1', type: 'Platform' },
              coords: [ 13.716492082528102, 51.02796893475141 ],
              arrival: 2020-07-31T01:30:00.000Z,
              departure: 2020-07-31T01:30:00.000Z
            }
          ],
          departure: {
            id: '33000742',
            name: 'Helmholtzstraße',
            city: 'Dresden',
            platform: undefined,
            time: 2020-07-31T01:18:00.000Z,
            coords: [ 13.725468471273134, 51.0255443264448 ],
            type: 'Stop'
          },
          arrival: {
            id: '33000135',
            name: 'Plauen Nöthnitzer Straße',
            city: 'Dresden',
            platform: { name: '1', type: 'Platform' },
            time: 2020-07-31T01:30:00.000Z,
            coords: [ 13.716492082528102, 51.02796893475141 ],
            type: 'Stop'
          },
          mode: {
            title: 'Fussweg',
            name: 'Footpath',
            iconUrl: 'https://m.dvb.de/img/walk.svg'
          },
          line: 'Fussweg',
          direction: '',
          diva: undefined,
          duration: 12,
          path: [
            [ 13.725468471273134, 51.0255443264448 ],
            [ 13.725454558079187, 51.025553521653286 ],
            ... 47 more items
          ]
        },
        {
          stops: [
            {
              id: '33000135',
              name: 'Plauen Nöthnitzer Straße',
              city: 'Dresden',
              type: 'Stop',
              platform: { name: '1', type: 'Platform' },
              coords: [ 13.716492082528102, 51.02796893475141 ],
              arrival: 2020-07-31T01:30:00.000Z,
              departure: 2020-07-31T01:30:00.000Z
            },
            {
              id: '33000134',
              name: 'Münchner Platz',
              city: 'Dresden',
              type: 'Stop',
              platform: { name: '1', type: 'Platform' },
              coords: [ 13.721883037345886, 51.02995723597058 ],
              arrival: 2020-07-31T01:31:00.000Z,
              departure: 2020-07-31T01:31:00.000Z
            },
            ... 4 more items
          ],
          departure: {
            id: '33000135',
            name: 'Plauen Nöthnitzer Straße',
            city: 'Dresden',
            platform: { name: '1', type: 'Platform' },
            time: 2020-07-31T01:30:00.000Z,
            coords: [ 13.716492082528102, 51.02796893475141 ],
            type: 'Stop'
          },
          arrival: {
            id: '33000032',
            name: 'Hauptbahnhof Nord',
            city: 'Dresden',
            platform: { name: '1', type: 'Platform' },
            time: 2020-07-31T01:36:00.000Z,
            coords: [ 13.735187096532323, 51.041491968478326 ],
            type: 'Stop'
          },
          mode: {
            title: 'Straßenbahn',
            name: 'Tram',
            iconUrl: 'https://www.dvb.de/assets/img/trans-icon/transport-tram.svg'
          },
          line: '3',
          direction: 'Wilder Mann',
          diva: { number: 11003, network: 'voe' },
          duration: 6,
          path: [
            [ 13.71646358720785, 51.02796935341722 ],
            [ 13.71649241447995, 51.02797791957738 ],
            ... 38 more items
          ]
        },
        ... 2 more items
      ],
      departure: {
        id: '33000742',
        name: 'Helmholtzstraße',
        city: 'Dresden',
        platform: undefined,
        time: 2020-07-31T01:18:00.000Z,
        coords: [ 13.725468471273134, 51.0255443264448 ],
        type: 'Stop'
      },
      arrival: {
        id: '33000037',
        name: 'Postplatz',
        city: 'Dresden',
        platform: { name: '4', type: 'Platform' },
        time: 2020-07-31T01:42:00.000Z,
        coords: [ 13.733543221907427, 51.05055101347277 ],
        type: 'Stop'
      },
      duration: 24,
      interchanges: 1
    },
    {
      nodes: [
        {
          stops: [
            {
              id: '33000742',
              name: 'Helmholtzstraße',
              city: 'Dresden',
              type: 'Stop',
              platform: undefined,
              coords: [ 13.725468471273134, 51.0255443264448 ],
              arrival: 2020-07-31T01:48:00.000Z,
              departure: 2020-07-31T01:48:00.000Z
            },
            {
              id: '33000135',
              name: 'Plauen Nöthnitzer Straße',
              city: 'Dresden',
              type: 'Stop',
              platform: { name: '1', type: 'Platform' },
              coords: [ 13.716492082528102, 51.02796893475141 ],
              arrival: 2020-07-31T02:00:00.000Z,
              departure: 2020-07-31T02:00:00.000Z
            }
          ],
          departure: {
            id: '33000742',
            name: 'Helmholtzstraße',
            city: 'Dresden',
            platform: undefined,
            time: 2020-07-31T01:48:00.000Z,
            coords: [ 13.725468471273134, 51.0255443264448 ],
            type: 'Stop'
          },
          arrival: {
            id: '33000135',
            name: 'Plauen Nöthnitzer Straße',
            city: 'Dresden',
            platform: { name: '1', type: 'Platform' },
            time: 2020-07-31T02:00:00.000Z,
            coords: [ 13.716492082528102, 51.02796893475141 ],
            type: 'Stop'
          },
          mode: {
            title: 'Fussweg',
            name: 'Footpath',
            iconUrl: 'https://m.dvb.de/img/walk.svg'
          },
          line: 'Fussweg',
          direction: '',
          diva: undefined,
          duration: 12,
          path: [
            [ 13.725468471273134, 51.0255443264448 ],
            [ 13.725454558079187, 51.025553521653286 ],
            ... 47 more items
          ]
        },
        {
          stops: [
            {
              id: '33000135',
              name: 'Plauen Nöthnitzer Straße',
              city: 'Dresden',
              type: 'Stop',
              platform: { name: '1', type: 'Platform' },
              coords: [ 13.716492082528102, 51.02796893475141 ],
              arrival: 2020-07-31T02:00:00.000Z,
              departure: 2020-07-31T02:00:00.000Z
            },
            {
              id: '33000134',
              name: 'Münchner Platz',
              city: 'Dresden',
              type: 'Stop',
              platform: { name: '1', type: 'Platform' },
              coords: [ 13.721883037345886, 51.02995723597058 ],
              arrival: 2020-07-31T02:01:00.000Z,
              departure: 2020-07-31T02:01:00.000Z
            },
            ... 4 more items
          ],
          departure: {
            id: '33000135',
            name: 'Plauen Nöthnitzer Straße',
            city: 'Dresden',
            platform: { name: '1', type: 'Platform' },
            time: 2020-07-31T02:00:00.000Z,
            coords: [ 13.716492082528102, 51.02796893475141 ],
            type: 'Stop'
          },
          arrival: {
            id: '33000032',
            name: 'Hauptbahnhof Nord',
            city: 'Dresden',
            platform: { name: '1', type: 'Platform' },
            time: 2020-07-31T02:06:00.000Z,
            coords: [ 13.735187096532323, 51.041491968478326 ],
            type: 'Stop'
          },
          mode: {
            title: 'Straßenbahn',
            name: 'Tram',
            iconUrl: 'https://www.dvb.de/assets/img/trans-icon/transport-tram.svg'
          },
          line: '3',
          direction: 'Wilder Mann',
          diva: { number: 11003, network: 'voe' },
          duration: 6,
          path: [
            [ 13.71646358720785, 51.02796935341722 ],
            [ 13.71649241447995, 51.02797791957738 ],
            ... 38 more items
          ]
        },
        ... 2 more items
      ],
      departure: {
        id: '33000742',
        name: 'Helmholtzstraße',
        city: 'Dresden',
        platform: undefined,
        time: 2020-07-31T01:48:00.000Z,
        coords: [ 13.725468471273134, 51.0255443264448 ],
        type: 'Stop'
      },
      arrival: {
        id: '33000037',
        name: 'Postplatz',
        city: 'Dresden',
        platform: { name: '4', type: 'Platform' },
        time: 2020-07-31T02:12:00.000Z,
        coords: [ 13.733543221907427, 51.05055101347277 ],
        type: 'Stop'
      },
      duration: 24,
      interchanges: 1
    },
    ... 3 more items
  ]
}

API Documentation

Table of contents

index.ts

Functions

coords

Find the coordinates for a given POI id.

function coords(id: string, timeout: number = 5000): Promise<number[]>;

Parameters

NameTypeDefault valueDescription
idstringthe POI ID
timeoutnumber5000the timeout of the request

Return type

Promise<number[] | undefined>


findAddress

Lookup address and nearby stops by coordinate.

function findAddress(lng: number, lat: number, timeout: number = 5000): Promise<IAddress>;

Parameters

NameTypeDefault valueDescription
lngnumberlongitude of the coordinate
latnumberlatitude of the coordinate
timeoutnumber5000the timeout of the request

Return type

Promise<IAddress | undefined>


findPOI

Search for POI in the network of the DVB.

function findPOI(searchString: string, timeout: number = 5000): Promise<IPoint[]>;

Parameters

NameTypeDefault valueDescription
searchStringstringthe name of the stop
timeoutnumber5000the timeout of the request

Return type

Promise<IPoint[]>


findStop

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

function findStop(searchString: string, timeout: number = 5000): Promise<IPoint[]>;

Parameters

NameTypeDefault valueDescription
searchStringstringthe name of the stop
timeoutnumber5000the timeout of the request

Return type

Promise<IPoint[]>


lines

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

function lines(stopID: string, timeout: number = 5000): Promise<ILine[]>;

Parameters

NameTypeDefault valueDescription
stopIDstringthe stop ID
timeoutnumber5000the timeout of the request

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, timeout: number = 5000): Promise<IMonitor[]>;

Parameters

NameTypeDefault valueDescription
stopIDstringID of the stop
offsetnumber0how many minutes in the future, 0 for now
amountnumber0number of results
timeoutnumber5000the timeout of the request

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], timeout: number = 5000): Promise<IPin[]>;

Parameters

NameTypeDefault valueDescription
swlngnumberthe longitude of the south west coordinate
swlatnumberthe latitude of the south west coordinate
nelngnumberthe longitude of the north east coordinate
nelatnumberthe latitude of the north east coordinate
pinTypesPIN_TYPE[]PIN_TYPE.stoparray of pin types
timeoutnumber5000the timeout of the request

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, timeout: number = 15000): Promise<IRoute>;

Parameters

NameTypeDefault valueDescription
originIDstringthe id of the origin stop
destinationIDstringthe id of the destination stop
timeDatenew Date()starting at what time
isArrivalTimebooleantrueis time the arrival time
timeoutnumber15000the timeout of the request

Return type

Promise<IRoute>

Interfaces

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

Properties

NameTypeOptional
numbernumberfalse
networkstringtrue

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

Properties

NameTypeOptional
namestringfalse
typestringfalse

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>;
    platformNr?: string;
    connections?: IConnection[];
    info?: string;
}

Properties

NameTypeOptional
idstringfalse
typePIN_TYPEfalse
namestringfalse
coordsArrayfalse
platformNrstringtrue
connectionsIConnection[]true
infostringtrue

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

Properties

NameTypeOptional
linestringfalse
modeIModetrue

IMode
interface IMode {
    title: string;
    name: string;
    iconUrl?: string;
}

Properties

NameTypeOptional
titlestringfalse
namestringfalse
iconUrlstringtrue

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

Extends

IPoint

Properties

NameTypeOptional
stopsIPoint[]false

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

Properties

NameTypeOptional
namestringfalse
modeIModetrue
divaIDivatrue
directionsstring[]false

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

Properties

NameTypeOptional
arrivalTimeDatefalse
scheduledTimeDatefalse
idstringfalse
linestringfalse
directionstringfalse
platformIPlatformtrue
arrivalTimeRelativenumberfalse
scheduledTimeRelativenumberfalse
delayTimenumberfalse
statestringfalse
modeIModetrue
divaIDivatrue

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

Properties

NameTypeOptional
idstringfalse
namestringfalse
citystringfalse
coordsArrayfalse

IPoint
interface IPoint extends ILocation {
    type: POI_TYPE;
}

Extends

ILocation

Properties

NameTypeOptional
typePOI_TYPEfalse

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

Extends

ILocation

Properties

NameTypeOptional
typestringfalse
platformIPlatformtrue
arrivalDatefalse
departureDatefalse

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

Extends

ILocation

Properties

NameTypeOptional
platformIPlatformtrue
timeDatefalse
typestringfalse

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

Properties

NameTypeOptional
stopsIStop[]false
departureIStopLocationtrue
arrivalIStopLocationtrue
modeIModetrue
linestringfalse
directionstringfalse
divaIDivatrue
durationnumberfalse
pathArray[]false

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

Properties

NameTypeOptional
departureIStopLocationtrue
arrivalIStopLocationtrue
durationnumberfalse
interchangesnumberfalse
nodesINode[]false

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

Properties

NameTypeOptional
originILocationtrue
destinationILocationtrue
tripsITrip[]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

NameValue
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

NameValue
stop"stop"
platform"platform"
poi"poi"
rentabike"rentabike"
ticketmachine"ticketmachine"
carsharing"carsharing"
parkandride"parkandride"
unknown"unknown"
6.2.0

5 months ago

6.1.1

12 months ago

6.1.0

12 months ago

6.0.1

4 years ago

6.0.0

5 years ago

5.1.1

5 years ago

5.1.0

5 years ago

5.0.2

5 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.3.7

7 years ago

4.3.6

7 years ago

4.3.5

7 years ago

4.3.4

7 years ago

4.3.3

7 years ago

4.3.2

7 years ago

4.3.1

7 years ago

4.3.0

7 years ago

4.2.2

7 years ago

4.2.1

7 years ago

4.2.0

8 years ago

4.0.3

8 years ago

4.0.2

8 years ago

4.0.1

8 years ago

4.0.0

8 years ago

3.2.1

9 years ago

3.1.1

9 years ago

3.1.0

9 years ago

3.0.0

9 years ago

2.0.0

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago