Amtrak


Disclaimer
This library and it's creator have no relation to Amtrak. Amtrak and the Atmrak 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';
fetchTrainData().then((trainData) => {
console.dir(trainData, { depth: null })
})
Fetching All Trains
import { fetchAllTrains } from 'amtrak';
fetchAllTrains().then((trainData) => {
console.dir(trainData, { depth: null })
})
Fetching Single Trains
import { fetchTrain } from 'amtrak';
fetchTrain(20).then((trainData) => {
console.dir(trainData, { depth: null })
})
Fetching All Stations
import { fetchAllStations } from 'amtrak';
fetchAllStations().then((stationData) => {
console.dir(stationData, { depth: null })
})
Fetching Single Stations
import { fetchStation } from 'amtrak';
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
.