esra
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

PGN Parser test workflow

Parse Chess PGN files in a type safe simple way.

Install

yarn add esra

Usage

You have a string of PGN separated by newlines:

let study = ' PGN PGN PGN '

There are two alternative methods to consume:

Get a type safe json structure:


import esra, { em } from 'esra';

esra(study); // returns Array<em.PGN> | undefined

See model.ts for the data structure.

Or use dis.Disect to dissect the json structure into callbacks on data:

  import esra, { dis } from 'esra';

  // these hooks will be called as the pgn is traversed.
  let d = {
    tag(name: string, value: string) {
      return name;
    },
    move(ply: number, move: any) {
      return {
        move,
        ply
      };
    },
    twomove(onemove: any, move: any) {
      return {
        onemove,
        move
      }
    },
    san(san: string) {
      return san;
    },
    sanWithExtra(san: string, extra: any) {
      return { san, extra };
    }
  };

  
  let ds = new dis.Disect(d);

  let model = esra(study);

  if (model) {
    ds.study(model);
  } else {
    // couldn't parse study
  }

PGN Format

Tags, Moves and Game Result is supported.

A Tag is [TagName, TagValue].

San moves, glyphs, one NAG, commentary is supported.

Rest of the spec is incompatible and esra will return undefined.

Readme

Keywords

Package Sidebar

Install

npm i esra

Weekly Downloads

0

Version

1.2.1

License

MIT

Unpacked Size

201 kB

Total Files

86

Last publish

Collaborators

  • eguneys