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

gtttools

v2.0.4

Published

A new, decent and possibly working public transport tracker for the city of Turin, Italy.

Downloads

14

Readme

GTTTools-core

A new, decent and possibly working public transport API wrapper for the city of Turin, Italy.

Core

This is the core package of the GTTTools application, an API wrapper and middleware meant for local or server side use, which provides a simplified interface for interacting with the GTT live public transportation API.

The API

GTTTools-core fetches its data from the same endpoint used by the GTT live tracker and many other services.
Here's why you should use GTTTools-core instead of different solutions:

  • GTTTools-core is entirely available in English, unlike the original data, which is partially written in Italian for seemingly no reason.
  • Requests made easy. Just worry about your app's logic, GTTTools-core will handle HTTP requests, headers and parameters for you.
  • Simplified polling. Enter your preferred polling interval to enjoy the fastest data available.
  • Easily accessible data. GTTTools-core removes redundant data and improves typings on the response objects.

Getting started

Download from npm using npm i gtttools.

Usage examples

GTTTools-core provides two classes: Stop and Route.

Stop

The Stop class represents a bus or tram stop. Each stop is assigned a number, which the Stop.poll(...) method takes as a parameter.

import { Stop } from 'GTTTools'

const myStop = new Stop();

myStop.poll(40, 1000);   //Poll stop 40 (Porta Nuova) every 1000 milliseconds
myStop.on('refresh', (passageData, stop) => {
    console.log(`Data on stop ${stop}`)
    /*  Your code here  */
    console.log(passageData);
});

myStop.stop();  //Stop the polling 

This returns an array of lines, stating the programmed and real time arrival date of the bus or tram. The lineID property may be used as a parameter for the Route class.

[  
  {
    line: '9',
    lineID: '9',
    direction: 'BARRIERA LANZO, PIAZZA STAMPALIA',
    realTime: [ 2022-10-21T20:07:00.000Z ],
    programmed: [ 2022-10-21T20:09:00.000Z, 2022-10-21T20:54:00.000Z ]
  },
  {
    line: '67',
    lineID: '67',
    direction: 'CITTADELLA, PIAZZA ARBARELLO',
    realTime: [ 2022-10-21T20:12:00.000Z ],
    programmed: [ 2022-10-21T20:16:00.000Z, 2022-10-21T20:46:00.000Z ]
  }
]

Note: this endpoint takes several seconds to load because of a slow endpoint on the GTT API.

Route

The Route class represents a bus or tram route (line). Each route is assigned a code, which the Route.poll(...) method takes as a parameter.

import { Route } from 'GTTTools'

const myRoute = new Route();

myRoute.poll('4', 1000);  //Poll route 4 every 1000 milliseconds
myRoute.on('refresh', (vehicleData, route) => {    
    console.log(`Data on route ${route}`)
    /*  Your code here  */
    console.log(vehicleData);
});

myVehicle.stop();  //Stop the polling

Note: despite often being a number, the route code is a string because it can sometimes include letters inside of it. Examples of this are: 9N, 72B and M1S.

This returns an array of vehicles, stating the latest available coordinates of the bus or tram. The id property may be used to identify the bus or tram model.

[
  {
    id: 6017,
    vehicleType: 'Tram',
    lat: 45.06237,
    lon: 7.67727,
    direction: 166,
    updated: 2022-10-21T20:13:00.000Z
  },
  {
    id: 6027,
    vehicleType: 'Tram',
    lat: 45.08133,
    lon: 7.68663,
    direction: 24,
    updated: 2022-10-21T20:12:00.000Z
  }
]

TypeScript

GTTTools-core is compatible with TypeScript. The module exports the the following TypeScript interfaces, useful to interact with the middleware:

Stop class:

interface passage {
  line: string,
  lineID: string,
  direction: string,
  realTime: Date[],
  programmed: Date[]
}

Route class:

interface vehicle {
  id: number,
  vehicleType: string,
  lat: number,
  lon: number,
  direction: number,
  updated: Date,
};