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

public-transport-ireland

v1.4.0

Published

Node.js module with utility functions to get real time data for Irish public transport (Irish Rail, Luas, Dublin Bus)

Downloads

24

Readme

public-transport-ireland

Node.js module with utility functions to get real time data for Irish public transport (Irish Rail, Luas, Dublin Bus)

npm version Monthly Downloads Build Status JavaScript Style Guide

Install

With NPM:

npm install --save public-transport-ireland

Requires Node.js v8+

Sample usage

This module contains several sub modules. You can globally import all submodules by doing something like this:

const publicTransport = require('public-transport-ireland')

// access dublinBus.getStops
console.log(publicTransport.dublinBus.getStops) // function

However, since every sub module might allocate resources (e.g. SOAP or HTTP clients) as soon as they are imported, it is recommended to directly import the sub modules that you want to use:

const dublinBus = require('public-transport-ireland/dublin-bus')

// access dublinBus.getStops
console.log(dublinBus.getStops) // function

Sub modules available

  • dublin-bus: require('public-transport-ireland/dublin-bus')
  • irish-rail: require('public-transport-ireland/irish-rail')
  • luas: require('public-transport-ireland/luas')

🚌 Dublin Bus

Allows to get all the stops and the real time information for a stop.

Exported items

  • getStops(): get information about all available stops
  • getRealTimeInfo(stopId: number): get real time information for a given bus stop

Examples

Get all the stops and then the real time information for the first stop:

'use strict'

const { getStops, getRealTimeInfo } = require('public-transport-ireland/dublin-bus')

async function main () {
  const allStops = await getStops()
  console.log('allStops', allStops)
  const realTimeDataForFirstStop = await getRealTimeInfo(allStops[0].code)
  console.log('realTimeDataForFirstStop', realTimeDataForFirstStop)
}

main()

This will print:

allStops [
  {
    id: 2,
    code: "2",
    longitude: -6.263695,
    latitude: 53.352241,
    description: 'Parnell Square, Parnell Street'
  },
  {
    id: 3,
    code: "3",
    longitude: -6.263783,
    latitude: 53.352307,
    description: 'Parnell Square, Granby Place'
  },
  // ...
]

realTimeDataForFirstStop [
  {
    lineName: '46A',
    destinationName: 'Phoenix Pk via Donnybrook',
    destination: '46A - Phoenix Pk via Donnybrook',
    expectedArrivalTime: '2019-09-22T16:59:59.000+01:00',
    vehicleAtStop: false,
    arrivingInMinutes: 5
  },
  {
    lineName: '38',
    destinationName: 'Damastown via Corduff',
    destination: '38 - Damastown via Corduff',
    expectedArrivalTime: '2019-09-22T17:04:05.000+01:00',
    vehicleAtStop: false,
    arrivingInMinutes: 9
  },
  // ...
]

🚂 Irish Rail

Allows to get all the stations and the real time information for a station.

Exported items

  • getStations(): get information about all available train stations
  • getRealTimeInfo(stationCode: string, direction?: Direction): Get information about trains arriving at a given station
  • Direction: an object that contains all the well known directions (key/value pairs)

Examples

Get all the available stations and then the real time information for the first station:

'use strict'

const { getStations, getRealTimeInfo } = require('public-transport-ireland/irish-rail')

async function main () {
  const allStations = await getStations()
  console.log('allStations', allStations)
  const realTimeDataForFirstStation = await getRealTimeInfo(allStations[0].code)
  console.log('realTimeDataForFirstStation', realTimeDataForFirstStation)
}

main()

This will print:

allStations [
  {
    id: 228,
    code: 'BFSTC',
    name: 'Belfast',
    longitude: -5.91744,
    latitude: 54.6123
  },
  {
    id: 238,
    code: 'LBURN',
    name: 'Lisburn',
    longitude: -6.04327,
    latitude: 54.514
  },
  // ...
]
realTimeDataForFirstStation [
  {
    code: 'A122',
    origin: 'Dublin Connolly',
    destination: 'Belfast',
    originTime: '2019-09-23T07:35:00.000+01:00',
    destinationTime: '2019-09-23T09:45:00.000+01:00',
    status: 'En Route',
    arrivingInMinutes: 2,
    minutesLate: 5,
    expectedArrivalTime: '2019-09-23T09:50:00.000+01:00',
    expectedDepartureTime: '2019-09-23T00:00:00.000+01:00',
    scheduledArrivalTime: '2019-09-23T09:45:00.000+01:00',
    scheduledDepartureTime: '2019-09-23T00:00:00.000+01:00',
    direction: 'Northbound',
    trainType: 'Train'
  },
  {
    code: 'A125',
    origin: 'Belfast',
    destination: 'Dublin Connolly',
    originTime: '2019-09-23T10:35:00.000+01:00',
    destinationTime: '2019-09-23T12:40:00.000+01:00',
    status: 'No Information',
    arrivingInMinutes: 47,
    minutesLate: 0,
    expectedArrivalTime: '2019-09-23T00:00:00.000+01:00',
    expectedDepartureTime: '2019-09-23T10:35:00.000+01:00',
    scheduledArrivalTime: '2019-09-23T00:00:00.000+01:00',
    scheduledDepartureTime: '2019-09-23T10:35:00.000+01:00',
    direction: 'Southbound',
    trainType: 'Train'
  },
  // ...
]

When getting real time information you can also pass an additional parameter to filter on a specific "direction" (e.g. "Southbound" or "Northbound") as in the following example:

'use strict'

const { getRealTimeInfo, Direction } = require('public-transport-ireland/irish-rail')

async function main () {
  const realTimeDataForAshtownSouthbound = await getRealTimeInfo('ASHTN', Direction.SOUTHBOUND)
  console.log('realTimeDataForAshtownSouthbound', realTimeDataForAshtownSouthbound)
}

main()

This should print something like this:

realTimeDataForAshtownSouthbound [
  {
    code: 'P740',
    origin: 'Maynooth',
    destination: 'Dublin Connolly',
    originTime: '2019-09-23T10:40:00.000+01:00',
    destinationTime: '2019-09-23T11:22:00.000+01:00',
    status: 'En Route',
    arrivingInMinutes: 1,
    minutesLate: 9,
    expectedArrivalTime: '2019-09-23T11:17:00.000+01:00',
    expectedDepartureTime: '2019-09-23T11:17:00.000+01:00',
    scheduledArrivalTime: '2019-09-23T11:07:00.000+01:00',
    scheduledDepartureTime: '2019-09-23T11:08:00.000+01:00',
    direction: 'Southbound',
    trainType: 'Train'
  },
  {
    code: 'P742',
    origin: 'Maynooth',
    destination: 'Dublin Connolly',
    originTime: '2019-09-23T11:40:00.000+01:00',
    destinationTime: '2019-09-23T12:22:00.000+01:00',
    status: 'No Information',
    arrivingInMinutes: 52,
    minutesLate: 0,
    expectedArrivalTime: '2019-09-23T12:07:00.000+01:00',
    expectedDepartureTime: '2019-09-23T12:08:00.000+01:00',
    scheduledArrivalTime: '2019-09-23T12:07:00.000+01:00',
    scheduledDepartureTime: '2019-09-23T12:08:00.000+01:00',
    direction: 'Southbound',
    trainType: 'Train'
  },
  // ...
]

Note that you can use the Direction object to get a list of well known directions.

🚃 Luas

Allows to get all the stops, stop status and the real time information for a stop.

Exported items

  • getStops(lineFilter?: Line): get all the available luas stop. Can filter by line
  • getRealTimeInfo(stopCode: string, directionFilter?: Direction): get realtime information for a given stop
  • getStopStatus(stopCode: string): get the status of a given stop
  • Line: an object that contains all the well known lines (key/value pairs)
  • Direction: an object that contains all the well known directions (key/value pairs)

Examples

Get all the available stops and then the real time information for the first stop:

'use strict'

const { getStops, getStopStatus, getRealTimeInfo } = require('public-transport-ireland/luas')

async function main () {
  const allStops = await getStops()
  console.log('allStops', allStops)

  const firstStopStatus = await getStopStatus(allStops[0].code)
  console.log('firstStopStatus', firstStopStatus)

  const firstStopRealTimeInfo = await getRealTimeInfo(allStops[0].code)
  console.log('firstStopRealTimeInfo', firstStopRealTimeInfo)
}

main()

This should print something like this:

allStops [
  {
    line: 'Luas Red Line',
    name: 'The Point',
    pronunciation: 'The Point',
    code: 'TPT',
    isParkRide: false,
    isCycleRide: false,
    latitude: 53.34835,
    longitude: -6.22925833333333,
    outboundStatusMessage: 'Services operating normally',
    outboundOperatingNormally: true,
    outboundForecastsEnabled: true,
    inboundStatusMessage: 'Services operating normally',
    inboundOperatingNormally: true,
    inboundForecastsEnabled: true
  },
  // ...
]
firstStopStatus [
  {
    direction: 'Inbound',
    statusMessage: 'Services operating normally',
    forecastsEnabled: true,
    operatingNormally: true
  },
  // ...
]
firstStopRealTimeInfo [
  {
    direction: 'Inbound',
    destination: 'No trams forecast',
    arrivingInMinutes: 0,
    expectedArrivalTime: '2019-09-23T20:01:46.000+01:00'
  },
  // ...
]

The getStops function accept an optional parameter to filter on the line. To get the stops only for the Red line you can do something like this:

'use strict'

const { Line, getStops } = require('public-transport-ireland/luas')

async function main () {
  const redLineStops = await getStops(Line.RED)
  console.log('redLineStops', redLineStops)
}

main()

This will print something like this:

redLineStops [
  {
    line: 'Luas Red Line',
    name: 'The Point',
    pronunciation: 'The Point',
    code: 'TPT',
    isParkRide: false,
    isCycleRide: false,
    latitude: 53.34835,
    longitude: -6.22925833333333,
    outboundStatusMessage: 'Services operating normally',
    outboundOperatingNormally: true,
    outboundForecastsEnabled: true,
    inboundStatusMessage: 'Services operating normally',
    inboundOperatingNormally: true,
    inboundForecastsEnabled: true
  },
  // ...
]

Note that you can use the Line object to get a list of well known lines.


The getRealTimeInfo function allows you to pass an optional parameter to filter on a given direction:

'use strict'

const { Direction, getRealTimeInfo } = require('public-transport-ireland/luas')

async function main () {
  const realTimeInboundInfoForDominic = await getRealTimeInfo('DOM', Direction.INBOUND)
  console.log('realTimeInboundInfoForDominic', realTimeInboundInfoForDominic)
}

main()

This will print something like this:

realTimeInboundInfoForDominic [
  {
    direction: 'Inbound',
    destination: 'Broombridge',
    arrivingInMinutes: 6,
    expectedArrivalTime: '2019-09-23T20:19:02.000+01:00'
  },
  {
    direction: 'Inbound',
    destination: 'Broombridge',
    arrivingInMinutes: 15,
    expectedArrivalTime: '2019-09-23T20:28:02.000+01:00'
  }
]

Note that you can use the Direction object to get a list of well known directions.

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub or PRs.

License

Licensed under MIT License. © Luciano Mammino.