@mliebelt/pgn-writer
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

In a nutshell ...

Provides base functionality (implemented in Javascript) to write PGN to a string. The input is the one produced by pgn-parser, and used as well by pgn-reader.

Goals

  • Implement the part of modules/pgn-reader/src/pgn.js, there write_pgn.
  • Provide a configuration that allows different output formats / options.
  • Allow to be used to do the following scenario
    1. Import a huge collection of PGN games (one file).
    2. Write info/warning/error messages on reading (not part of this library).
    3. Export those games (or a subset of it) in a standard format: This is what is provided by this library.
    4. Allow variants in writing: strip tags; strip variants; strip kind of comments (arrows and circles, time comments, ...); strip NAGs; use a different language for export (by giving the locale)

See the annotated spec that should be sufficient for guiding the implementation.

Usage

The following is pseudo-code, the interface is not defined completely and will change in the future. But I moved the source to typescript, and have added type annotations where necessary. Look at the annotations PgnGame and PgnWriterConfiguation which are currently the only arguments to the main function. The function getGame(<index>) of pgn-reader not yet exists, but will be added in the next version.

import {PgnReader} from '@mliebelt/pgn-reader'
import {writeGame} from '@mliebelt/pgn-writer'

let game = new PgnReader({ pgn: '1. e4 *', ... }).getGame(0)
let resultPGN = writeGame(game, { config2: 'param', ... })

Package Sidebar

Install

npm i @mliebelt/pgn-writer

Weekly Downloads

60

Version

1.0.5

License

Apache-2.0

Unpacked Size

25.8 kB

Total Files

4

Last publish

Collaborators

  • mliebelt