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

digitransit

v1.0.11

Published

Digitransit module for Node.js. Supports Digitransit's Routing API for trip planning and Geocoding API for the address search and lookup.

Downloads

4

Readme

Digitransit

Node.js module for Digitransit Routing API and Geocoding API. Module converts a Javascript object into a GraphQL query and returns results as a promise.

About

We created this module for Tripper to generate basic itineraries for daily allowance (päiväraha) and distance compensation (kilometrikorvaus) suggestions.

Tripper logo

Getting Started

Install module, generate query object for either routing or address search and enjoy results.

See test.js for a sample tripObject and addressObject that can be passed to the module.

For the options regarding travel modes etc. please, refer to the original Digitransit docs at https://digitransit.fi/en/developers/services-and-apis/1-routing-api/

Installation

Using npm:

$ npm install --save digitransit

Test

$ npm test

Use

const digitransit = require('digitransit');

// First routing, then addressSearch and last address lookup

// FIRST: Routing API
// Query where we leave from Tampere and go directly to Helsinki
// Modes are Transit and walking and we want to depart asap
// We only want one itinerary
// We could provide the waypoints in an array of objects with latitude (lat)
// and longitude (lon) for each stop in RIGHT order
const tripObject = {
  waypoints: [],
  from: {
    lat: 61.502659,
    lon: 23.779152,
  },
  to: {
    lat: 60.171570,
    lon: 24.945303,
  },
  itineraries: 1,
  modes: ['walk', 'transit'],
  arrivalTime: false,
  time: new Date(),
};

digitransit.routing(tripObject).then((response) => {
    console.log(response)
    /*
    Should be something like:
    {
      success: true,
      itineraries: [
        {
          legs: [
          { startTime: 1499165526000,
            endTime: 1499166150000,
            mode: 'WALK',
            duration: 624,
            distance: 774.9380000000001,
            agency: null },
          { startTime: 1499166151000,
            endTime: 1499171665000,
            mode: 'RAIL',
            duration: 5514,
            distance: 165864.96795957946,
            agency: { name: 'VR Osakeyhtiö' } },
          { startTime: 1499171666000,
            endTime: 1499171898000,
            mode: 'WALK',
            duration: 232,
            distance: 264.704,
            agency: null }
          ]
        }
      ]
    }
    */
}).catch((error) => {
  console.log(error);
});

// SECOND Address API
// Query an address in Tampere
// We want only one result (the best) and address names in Finnish
const addressObject = {
  text: 'Tammelan puistokatu 22, 33100 Tampere',
  size: 1,
  lang: 'fi'
};
digitransit.addressSearch(addressObject).then((response) => {
    console.log(response);
    /*
    Should be something like:
    {
      success: true,
      results:
       [
        {
          type: 'Feature',
          geometry: { type: 'Point', coordinates: [Object] },
          properties:
           { id: 'polyline:71199',
             gid: 'openstreetmap:street:polyline:71199',
             layer: 'street',
             source: 'openstreetmap',
             source_id: 'polyline:71199',
             name: 'Tammelan puistokatu',
             street: 'Tammelan puistokatu',
             postalcode: '33100',
             postalcode_gid: 'whosonfirst:postalcode:421475007',
             confidence: 0.9388888888888888,
             accuracy: 'centroid',
             country: 'Suomi',
             country_gid: 'whosonfirst:country:85633143',
             country_a: 'FIN',
             region: 'Pirkanmaa',
             region_gid: 'whosonfirst:region:85683099',
             localadmin: 'Tampere',
             localadmin_gid: 'whosonfirst:localadmin:907199231',
             locality: 'Tampere',
             locality_gid: 'whosonfirst:locality:101748431',
             neighbourhood: 'Tammela',
             neighbourhood_gid: 'whosonfirst:neighbourhood:1108728527',
             label: 'Tammelan puistokatu, Tampere' },
             bbox: [ 23.779277, 61.498954, 23.779724, 61.506702 ]
        }
      ]
    }
    */
}).catch((error) => {
  console.log(error);
});

// THIRD Address lookup
const coordinates = {
  lat: 61.502659,
  lon: 23.779152,
  size: 1,
  lang: 'fi',
};
digitransit.addressLookup(coordinates).then((response) => {
    console.log(response);
    /*
    Should be something like:
    {
      success: true,
      results:
        [
          {
            type: 'Feature',
            geometry: { type: 'Point', coordinates: [Object] },
            properties:
              {
                id: 'fi/pirkanmaa:103430467N-1',
                gid: 'openaddresses:address:fi/pirkanmaa:103430467N-1',
                layer: 'address',
                source: 'openaddresses',
                source_id: 'fi/pirkanmaa:103430467n-1',
                name: 'Tammelan Puistokatu 24',
                housenumber: '24',
                street: 'Tammelan Puistokatu',
                postalcode: '33100',
                postalcode_gid: 'whosonfirst:postalcode:421475007',
                confidence: 0.8,
                distance: 0.012,
                accuracy: 'point',
                country: 'Suomi',
                country_gid: 'whosonfirst:country:85633143',
                country_a: 'FIN',
                region: 'Pirkanmaa',
                region_gid: 'whosonfirst:region:85683099',
                localadmin: 'Tampere',
                localadmin_gid: 'whosonfirst:localadmin:907199231',
                locality: 'Tampere',
                locality_gid: 'whosonfirst:locality:101748431',
                neighbourhood: 'Tammela',
                neighbourhood_gid: 'whosonfirst:neighbourhood:1108728527',
                label: 'Tammelan Puistokatu 24, Tampere'
              }
            }
        ]
    }
    */
}).catch((error) => {
  console.log(error);
});

Changelog

1.0.10 = Added background infromation about the project 1.0.9 = Changed the query object in the sample from isArrivalTime to arrivalTime