npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cornelius

v2.1.0

Published

Get data provided by MLB's public lookup routes.

Downloads

31

Readme

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