Giter Site home page Giter Site logo

maz-bil / amtrak Goto Github PK

View Code? Open in Web Editor NEW

This project forked from piemadd/amtrak

0.0 0.0 0.0 9.38 MB

NPM library to get Amtrak tracking data.

License: GNU Affero General Public License v3.0

Shell 0.58% JavaScript 18.32% TypeScript 80.75% Nix 0.35%

amtrak's Introduction

Amtrak

Amtrak.js Logo

Amtrak.js - Unofficial Amtrak Library - The easiest way to track Amtrak Trains Programmatically! | Product Hunt

Disclaimer

This library and its creator have no relation to Amtrak. Amtrak and the Amtrak Logo are trademarks of The National Railroad Passenger Corporation (NRPC). The API endpoint used is not intended for use outside of Amtrak's Train Tracking map.

Installation

It'n an NPM package lol:

npm install amtrak

Documentation

View on Github

Demo Repl

Here is a demo Repl you can either just simply run or even fork (all in your browser) to see what this library is capable of: https://replit.com/@piemadd/Amtrakjs-Example

TS Examples

As this library was written in TypeScript, it is naturally easy to use it:

Fetching All Data

import { fetchTrainData } from 'amtrak';

//fetches data, cleans it, and then prints to terminal
fetchTrainData().then((trainData) => {
	console.dir(trainData, { depth: null })
})

Fetching All Trains

import { fetchAllTrains } from 'amtrak';

//fetches all trains and then prints to terminal
fetchAllTrains().then((trainData) => {
	console.dir(trainData, { depth: null })
})

Fetching Single Trains

import { fetchTrain } from 'amtrak';

//fetches all trains with the number 20 (crescent) and then prints to terminal
fetchTrain(20).then((trainData) => {
	console.dir(trainData, { depth: null })
})

Fetching All Stations

import { fetchAllStations } from 'amtrak';

//fetches all stations and then prints to terminal
fetchAllStations().then((stationData) => {
	console.dir(stationData, { depth: null })
})

Fetching Single Stations

import { fetchStation } from 'amtrak';

//fetches all station data for CHI (chicago) and then prints to terminal
fetchStation('CHI').then((stationData) => {
	console.dir(stationData, { depth: null })
})

JS Example

And of course, as the TS is compliled to JS, you can use that as well. The only real difference between the two is how you (generally) import, so everything else is the same. The only difference here is that you can import from in ts, but you require the whole module is js.

const amtrak = require("amtrak");
amtrak.fetchTrainData().then((trainData) => {
    console.dir(trainData, { depth: null })
});

(wait they're like the same lmao)

Contributing

I don't currently have any official contributing templates, but please make sure to add some testing code to testing/src/testAll.ts. Anything you add should take one of the existing types and return a modified version of it or a new type which you define in src/types/types.ts.

amtrak's People

Contributors

piemadd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.