JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q56962F
  • License ISC

Package Exports

  • retrosheet-parse

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (retrosheet-parse) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

retrosheet-parser

retrosheet-parser is a library that parses Retrosheet files.

Installation

npm i retrosheet-parse

Usage

const { parseFile, parseGames } = require('retrosheet-parse')

parseFile(pathtoFile, [options])

pathToFile: relative path to your Retrosheet file

options: Optional options array (see below for availble option)

Takes a standard Retrosheet file and returns a list of raw games files. For example this (very) truncated game file:

id,ANA201904040
version,2
info,visteam,TEX
start,choos001,"Shin-Soo Choo",0,1,9
start,harvm001,"Matt Harvey",1,0,1
play,1,0,choos001,22,FBBCH,HP
com,"On-field Delay"
data,er,volqe001,2
id,ANA201904040
version,2
info,visteam,TEX
start,choos001,"Shin-Soo Choo",0,1,9
start,harvm001,"Matt Harvey",1,0,1
play,1,0,choos001,22,FBBCH,HP
com,"On-field Delay"
data,er,volqe001,2

will return an array with 2 game arrays in it:

[
      [
        'id,ANA201904040',
        'version,2',
        'info,visteam,TEX',
        'start,choos001,"Shin-Soo Choo",0,1,9',
        'start,harvm001,"Matt Harvey",1,0,1',
        'play,1,0,choos001,22,FBBCH,HP',
        'com,"On-field Delay"',
        'data,er,volqe001,2'
      ],
      [
        'id,ANA201904040',
        'version,2',
        'info,visteam,TEX',
        'start,choos001,"Shin-Soo Choo",0,1,9',
        'start,harvm001,"Matt Harvey",1,0,1',
        'play,1,0,choos001,22,FBBCH,HP',
        'com,"On-field Delay"',
        'data,er,volqe001,2'
      ]
    ]

parseGames(pathtoFile, [options])

pathToFile: relative path to your Retrosheet file

options: Optional options array (see below for availble option)

Parses a Retrosheet file but returns a list of Game objects. Type definitions for returned data:

type Player = {
  id: string
  name: string
  position: number
  type: 'sub' | 'start'
}

type Comment = {
  type: 'comment'
  text: string
}

type AtBat = {
  type: 'at-bat'
  playerId: string
  count: string
  pitchSequence: string
  result: string
}

type GameplayEvent = AtBat | Comment

type Lineup = Player[][]

type Game = {
  id: string
  info: {
    visteam: string
    hometeam: string
    site: string
    date: string
    number: string
    starttime: string
    daynight: string
    usedh: string
    umphome: string
    ump1b: string
    ump2b: string
    ump3b: string
    howscored: string
    pitches: string
    oscorer: string
    temp: string
    winddir: string
    windspeed: string
    fieldcond: string
    precip: string
    sky: string
    timeofgame: string
    attendance: string
    wp: string
    lp: string
    save: string
  }
  version: string
  lineup: {
    home: Lineup
    visiting: Lineup
  }
  data: {
    er: {
      [playerId: string]: number
    }
  }
  play: {
    home: GameplayEvent[][]
    visiting: GameplayEvent[][]
  }
}

Development

This project is still very rough and new. Also the fact that you know what Retrosheet files are and also what npm is means you could be very valuable to its development, so feel free to contribute or submit issues for improvement!