mlb-game-day
TypeScript icon, indicating that this package has built-in type declarations

0.8.0 • Public • Published

mlb-game-day

A JavaScript wrapper around the MLB Game Day API that can be used on the server or browser.

Install

$ npm install mlb-game-day -S

Use with TypeScript

You can use this library with TypeScript. To do this, you'll also need to grab a couple external type definition dependencies (axios and es6-promise).

I use typings to handle TypeScript type definition dependencies.

$ npm install typings -g

then from the directory of your application

$ typings install axios es6-promise --ambient

typings will install the type definitions to a typings folder which contains a main.d.ts file which can referenced from your project's typescript config.

API

Methods

Methods

gameIds(date)

Retrieves a list of game id's for a given date. If no date is provided, the current date is used.

Arguments

  1. date (Date): A date for which game id's will be retrieved.
Returns

(Axios.IPromise<string[]>): A list of string id's.

Example
import { gameIds } from 'mlb-game-day';
 
const date = new Date('4/8/2016');
 
gameIds(date).then(console.log);
 
// ['2016_04_08_nyamlb_detmlb_1', ... ]

getGameBoxScoreById(id)

Retrieves the box score for the given game id.

Arguments

  1. id (String): The game id
Returns

(Promise): The box score for the given id.

Example
import { gameIds, getGameBoxScoreById } from 'mlb-game-day';
 
const date = new Date('4/8/2016');
 
gameIds(date).then(ids => {
  getGameBoxScoreById(ids[0]).then(console.log)
});
 
// { home_sname: 'San Francisco', ... }

getGameEventsById(id)

Retrieves the game events for the given game id.

Arguments

  1. id (String): The game id
Returns

(Promise): The events for the given id.

Example
import { gameIds, getGameEventsById } from 'mlb-game-day';
 
const date = new Date('4/8/2016');
 
gameIds(date).then(ids => {
  getGameEventsById(ids[0]).then(console.log)
});
 
// { inning: [ { num: 1, ... }, ... ], ... }

Use Locally

$ npm install && npm run typings

LICENSE

MIT

Readme

Keywords

Package Sidebar

Install

npm i mlb-game-day

Weekly Downloads

0

Version

0.8.0

License

MIT

Last publish

Collaborators

  • mikedub