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

retrosheet-parse

v0.8.3

Published

retrosheet-parse is a library that parses [Retrosheet](https://www.retrosheet.org/) files.

Downloads

178

Readme

retrosheet-parse

retrosheet-parse is a library that parses Retrosheet files.

Installation

npm i retrosheet-parse

Usage

retrosheet-parse exposes 2 main functions. Both take a relative path your Retrosheet file and a set of optional options to generate an output file which are

export type FileOptions = {
  outputPath?: string // where the generated file will be outputted
  filename?: string // what to name that file (defaults to result.txt)
}

If you don't provide the options, no file is generated

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

const rawGames = await parseFile('./my/retrosheet/file')

const formattedGames = await parseGames('./my/retrosheet/file', {
  outputPath: './results',
  filename: 'games.txt'
})

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 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 promise that resolves 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!