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

blekingetrafiken

v0.1.1

Published

An API to retrieve public transport information, schedules and routes in Blekinge

Downloads

5

Readme

Blekingetrafiken API for NodeJS

A fully async API written in ES6 for retrieval of public transport information, schedules and routes in Blekinge


npm badge

Setting up

Installing
npm install blekingetrafiken
Quickstart
const api = require('blekingetrafiken');

// Fetch departures
api.fetchDepartures()
.then(departures => {
  const departure = departures[0];
  console.log(`A transportation of type '${departure.type}' (line ${departure.name}) is departing ${departure.onSchedule ? 'on schedule' : 'later than planned'} from stop point ${departure.stopPoint}`);
});
> A transportation of type 'Stadsbuss' (line 6) is departing on schedule from stop point A

Documentation

API
  const api = require('blekingetrafiken');
  api.fetchDepartures(from);
  api.searchJourneys(from, to, options);
  api.searchPoints(query);
  api.searchStops(query);
  api.fetchInfo();
  api.searchTimetable(line);
fetchDepartures
  const from = 'Kungsmarken';
  const departures = await api.fetchDepartures(from);
  console.log(departures);
[
  {
    name: '1',                           // The name of the bus (line)
    run: 26,                             // The current run the bus is on
    type: 'Stadsbuss',                   // The type of transportation - see below
    modeId: NaN,                         // The transportation mode - see below
    modeName: 'Stadsbuss/tätortstrafik', // Mode name
    trainNumber: 0,                      // Similar to name, applicable to trains
    towards: 'Lyckeby',                  // The current direction of the bus
    operatorId: 13,                      // The id of the current operator
    operatorName: null,                  // The operator name (usually Bergkvarabuss)
    onSchedule: true,                    // Whether or not the transportation is on schedule
    stopPoint: 'B',                      // At what point the bus will stop. Usually A or B
    realTime: {
      deviation: NaN,                    // Amount of delay in minutes
      effect: null                       // The effect of the delay - see below
    }
  }
  ...
]
Transportation types
  Stad (Stadsbuss)
  Land (Regionbuss),
  K-buss (Kustbussen),
  Ö-Tåg (Öresundståg),
  Båt,
  P-Tåg(Pågatåg),
  Tåg(Krösatåg)
Transportation modes

Some sort of yet to be determined bitmask of selected transportation modes (biking / walking / taking the bus).

Known values:

  • 1, stadsbuss
  • 2, regionbuss
  • 4095, every possible transportation mode
Realtime effects

Known values:

  • 'NONE', the usual effect. No delay
  • 'PASSED', the transportation has passed the stop
  • 'CRITICAL', the transportation is heavily delayed
  • '', no known effect
searchJourneys
  const from = 'Kungsmarken';
  const to = 'Kungsplan';
  const journeys = await api.fetchJourneys(from);
  console.log(departures);
[
  {
    departure: '2017-10-31T20:12:00',
    arrival: '2017-10-31T20:24:00',
    walkDistance: { departure: 0, arrival: 0 },
    changes: 0,
    zones: 1,
    zoneName: 'Karlskrona tätort',
    guaranteed: true,
    co2Factor: 10,
    co2Value: 0,
    prices: { adult: 24, youth: 14, family: 43 },
    discountedPrices: { adult: 19.2, youth: 11.2, family: 34.4 },
    routeLinks: [],
    distance: 5389,
    from:
    { id: '10001067',
    name: 'Kungsmarken A-huset',
    type: 'stop',
    coordinates: [Object],
    distance: NaN },
    to:
    {
      id: '10001001',
      name: 'Kungsplan Karlskrona',
      type: 'stop',
      coordinates: [Object],
      distance: NaN
    }
  }
]
searchPoints
  const query = 'Park';
  const filter = ['point of interest']
  const points = await api.searchPoints(query, { filter });
  console.log(points);
[
  {
    id: '10001601',
    name: 'Karlskrona centrum Parkgatan',
    type: 'stop',
    coordinates: {
      latitude: 6226117,
      longitude: 1486398
    },
    distance: NaN
  },
  {
    id: '10001149',
    name: 'Parkvägen Jämjö',
    type: 'stop',
    coordinates: {
      latitude: 6229271,
      longitude: 1502720
    },
    distance: NaN
  }
  ...
]
searchStops
  const query = 'Campus Gräsvik';
  const stops = await api.searchStops(query);
  console.log(stops);
[
  {
    id: '10001927',
    name: 'Campus Gräsvik',
    type: 'stop',
    coordinates: {
      latitude: 6228063,
      longitude: 1486813
    },
    distance: NaN
  }
]
fetchInfo
  const info = await api.fetchInfo();
  console.log(info);
Vägarbete på väg 22
searchTimetable
  const query = '1';
  const timetables = await api.searchTimetable(query);
  console.log(timetables);
[
  {
    type: 'Stad',
    name: '2',
    header: 'Jämjö - Lyckeby - Centrum',
    validFrom: '2017-08-21',
    validTo: '2018-06-17',
    url: '[removed url to pdf file]'
  },
  ...
]

Contributing

Any contribution is welcome. If you're not able to code it yourself, perhaps someone else is - so post an issue if there's anything on your mind.

Development

Clone the repository:

git clone https://github.com/AlexGustafsson/blekingetrafiken.git && cd blekingetrafiken

Set up for development:

npm install

Follow the conventions enforced:

npm test
npm run-script lint
npm run-script coverage
npm run-script check-duplicate-code

Disclaimer

Although the project is very capable, it is not built with production in mind. Therefore there might be complications when trying to use the API for large-scale projects meant for the public. The API was created to easily fetch public transport information, schedules and routes in Blekinge programmatically and as such it might not promote best practices nor be performant. This project is not in any way affiliated with Blekingetrafiken or Blekinge.