cornelius

2.1.0 • Public • Published

Table of Contents

Cornelius

Cornelius let's you grab MLB data via MLBAM's public lookup routes. All of the data Cornelius returns is property of MLB Advanced Media, and subject to their usage terms.

Getting Started

  yarn add cornelius
  const cornelius = require('cornelius');

Usage

cornelius.playerSearch

Search for players by name.

options should be an object. If you provide no search query, playerSearch will return an empty array.

Parameters

  • options Object Options object.
    • options.query string Player name.
    • options.active boolean Set to false for historic players. (optional, default true)
    • options.prune boolean Prune the data. (optional, default true)

Examples

Active player search

cornelius.playerSearch({ query: 'wright' })
  .then(function (data) {
     // do stuff with search results
  })
  .catch(function (error) {
     // handle error
  });

Historic player search

cornelius.playerSearch({ query: 'williams', active: false })
    .then(function (data) {
      // do stuff with search results
    })
    .catch(function (error) {
      // handle error
    });

Returns (Array | Object) Array of pruned search results or MLB search_player_all JSON data.

cornelius.getPlayer

Takes a player's ID and returns their information.

options should be an object. If you provide no player ID, or an incorrect one, getPlayer will return an empty object.

Parameters

  • options Object Options object.
    • options.player_id string Player's ID.
    • options.prune boolean Prune the data. (optional, default true)

Examples

Get a player by ID

cornelius.getPlayer({ player_id: '529518' })
 .then(function (data) {
  // do stuff with player info
 })
 .catch(function (error) {
  // handle error
 });

Returns Object Pruned player object or MLB player_info JSON data.

cornelius.getStats

Takes a player's ID and returns their stats.

options should be an object. If you provide no player ID, or an incorrect one, getStats returns an empty array. If no year is provided, getStats returns all available stats for the given player.

Parameters

  • options Object Options object.
    • options.player_id string Player's ID.
    • options.season string? The season to get stats for.
    • options.pitching boolean Return pitching stats instead. (optional, default false)
    • options.prune boolean Prune the data. (optional, default true)

Examples

Get a player's hitting stats

cornelius.getStats({ player_id: '493316' })
  .then(function (data) {
    // do stuff with stats data
  })
  .catch(function (error) {
    // handle error
  });

Get a player's pitching stats for the 2017 season

cornelius.getStats({ player_id: '592789', pitching: true, season: '2017' })
  .then(function (data) {
    // do stuff with stats data
  })
  .catch(function (error) {
    // handle error
  });

Returns (Array | Object) Array of pruned stats or MLB sport_[statType]_tm JSON data.

cornelius.getRoster

Takes a team's ID and returns their 40 man, or all time roster.

The season property is a string of two years which mark the start and end seasons of the all time rosters you're requesting. Providing a single year will return only that years roster.

Omitting the season property will return a team's current 40 man roster.

options should be an object. If you provide no team ID, or an incorrect one, getRoster returns an empty array.

Parameters

  • options Object Options object.
    • options.team_id string Team's ID.
    • options.season string? Season to get roster for.
    • options.short boolean Return full player info with roster. (optional, default false)
    • options.prune boolean Prune the data. (optional, default true)

Examples

Get a team's roster by ID

cornelius.getRoster({ team_id: '121' }) // New York Mets
  .then(function (data) {
    // do stuff with roster data
  })
  .catch(function (error) {
    // handle error
  });

Get a team's cumulative roster for the seasons beginning 2016 and ending 2017

cornelius.getRoster({ team_id: '121', season: '2016 2017' })
  .then(function(data) {
    // do stuff with roster data
  })
  .catch(function (error) {
    // handle error
  });

Returns (Array | Object) Pruned roster or MLB roster_40 | roster_team_alltime JSON data.

License

MIT

Dependents (0)

Package Sidebar

Install

npm i cornelius

Weekly Downloads

2

Version

2.1.0

License

MIT

Unpacked Size

123 kB

Total Files

29

Last publish

Collaborators

  • appac