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

sncf

v0.6.0

Published

SNCF API client

Downloads

6

Readme

sncf

JavaScript client for the sncf API. Complies with the friendly public transport format. Inofficial, using endpoints by SNCF. Ask them for permission before using this module in production. Work in progress.

npm version Build Status Greenkeeper badge dependency status license fptf version chat on gitter

Installation

npm install --save sncf

Usage

This package contains data in the Friendly Public Transport Format.

stations(query)

Using sncf.stations, you can search train stations operated by SNCF.

const stations = require('sncf').stations

stations("Montpellier")
.then(console.log)
.catch(console.error)

Returns a Promise that will resolve in an array of stations in the Friendly Public Transport Format which looks as follows:

[
    {
        type: "station",
        id: "FRMPL",
        name: "Montpellier Saint-Roch (Occitanie)"
    }
    // …
]

journeys(origin, destination, date = new Date(), opt = {})

Using sncf.journeys, you can get directions and prices for routes from A to B. origin and destination can be station ids or FPTF station objects.

const journeys = require('sncf').journeys

const frankfurt = 'DEFRA'
const lyon = {type: 'station', id: 'FRLYS'}

journeys(frankfurt, lyon, new Date(), {duration: 24*60*60*1000})
.then(console.log)
.catch(console.error)

defaults, partially overridden by the opt parameter, looks like this:

const defaults = {
    duration: 6*60*60*1000  // searches for journeys in the next 6 hours starting at 'date' (parameter). Warning: Spawns multiple requests, may take a couple of seconds for longer durations!
    direct: false,  // direct connections only
    class: 2, // one of [1, 2]
	via: null, // station code or object
	language: 'fr',
	country: 'FR', // probably influences price currency (?)
}

Returns a Promise that will resolve with an array of journeys in the Friendly Public Transport Format which looks as follows. Please note that the results are not fully spec-compatible since arrival and departure Date strings don't contain the station timezones, because the API doesn't provide this information.

[
    {
        type: "journey",
        id: "3c9cb584-c16a-43ca-84fa-f89a610e9d82",
        legs: [
            {
                origin: "DEFRS",
                destination: "CHAJP",
                departure: "2018-03-27T04:02:00+01:00",
                arrival: "2018-03-27T07:20:00+01:00",
                line: {
                    type: "line",
                    id: "401",
                    name: "Train 401",
                    mode: "train",
                    vehicleType: "ONL",
                    services: [],
                    operator: "OE"
                },
                operator: "OE",
                schedule: "defrs-2018-03-27t04-02-00-01-00-chajp-2018-03-27t07-20-00-01-00"
            }
            // …
        ],
        price: {
            amount: 86,
            currency: "EUR",
            fares: [
                {
                    price: {
                        amount: 121,
                        currency: "EUR"
                    },
                    model: "SEMIFLEX",
                    appliedDiscount: 0,
                    passengers: [
                        {
                            clientId: "0",
                            travelerId: null,
                            price: 121,
                            age: "ADULT",
                            fidelityCard: "NONE",
                            fidelityPoints: null,
                            promoCodeType: null,
                            fareInformations: [
                                {
                                    fareName: "TARIF NORMAL ADULTE",
                                    fareCondition: "Billet remboursable sans frais jusqu'à 15 jours avant le départ, avec une pénalité de 50% à partir de 14 jours et jusqu'à 1 jours avant le départ. Billet non remboursable à partir de 1 jours avant le départ.",
                                    fareCode: "AFAD",
                                    fareSpecificRule: null,
                                    fareSequence: null,
                                    cosLevel: null,
                                    returnMandatory: false,
                                    passengerType: "PT00AD",
                                    classOfService: "B",
                                    segmentId: 6,
                                    passengerClientId: "0",
                                    promoCodeApplied: false,
                                    fixedPriceCuiQuotation: false,
                                    fakeFare: false
                                }
                                // …
                            ],
                            passengerType: "HUMAN",
                            encartedPrems: false,
                            specificSeatRequired: true,
                            hanInformation: null,
                            promoCodeApplied: false
                        }
                    ],
                    animals: [],
                    bookingFee: {
                        amount: 5,
                        type: "FDD"
                    },
                    bicycle: false,
                    placementOptions: true
                }
                // …
            ]
        },
        isRealTime: false
    }
    // …
]

See also

  • FPTF - "Friendly public transport format"
  • FPTF-modules - modules that also use FPTF

Contributing

If you found a bug, want to propose a feature or feel the urge to complain about your life, feel free to visit the issues page.