1.0.1 • Published 5 years ago
@hockeybots/slapshot v1.0.1
slapshot
slapshot is an NHL API library written in TypeScript.
Installation
With yarn
yarn add @hockeybots/slapshot
With npm
npm i @hockeybots/slapshot
Quick start example
With async/await
import idx from 'idx';
import slapshot from '@hockeybots/slapshot';
...
/**
* Fetch a teams data asynchronously
* returning an array of Team objects
*/
const teams = await slapshot.Teams(1).data();
const team = idx(teams, _ => _[0]);
if(team) {
console.log(`The ${team.teamName} first appeared in ${team.firstYearOfPlay}`);
}
With vanilla promises
import idx from 'idx';
import slapshot from '@hockeybots/slapshot';
...
/**
* Fetch a teams data asynchronously
* returning an array of Team objects
*/
slapshot
.Teams(1)
.data()
.then((teams) => {
const team = idx(teams, _ => _[0]);
if(team) {
console.log(`The ${team.teamName} first appeared in ${team.firstYearOfPlay}`);
}
})
.catch(console.error);
Fetch multiple teams
import slapshot from '@hockeybots/slapshot';
...
/**
* Fetch multiple teams data asynchronously
* returning an array of Team objects
*/
const teams = await slapshot.Teams(1,2,3,4).data();
teams.forEach(team =>
console.log(`The ${team.teamName} first appeared in ${team.firstYearOfPlay}`)
);