This package is a javascript PGN parser that transforms PGN files into chess "moments". In its simplest form, a chess "moment" has a chess move and its corresponding FEN.
Chess moments includes comments, shapes, variations, special characters, everything that you need in order to correctly display a chess game in javascript.
npm i chess-moments
# or
yarn add chess-moments
The API returns various arrays of objects (chess moments).
These chese moments have specific keys like move
, fen
, depth
and index
The first chess moment is always an object without the move
key.
It only has fen
, depth
, index
and optionally comment
or shapes
.
{
"move": "e4",
"fen": "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1",
"comment": "Opening the queen and the bishop",
"depth": 1
}
Returns a single level deep array of chess moments.
The depth
key delimits between variants and subvariants played in the chess game.
Returns a two level deep array of chess moments. The first level splits between variants and subvariants played in the chess game.
Returns a two level deep array of chess moments. It is useful for hiding future moves in chess training.
Adds a new move to the chess tree
Move forward in the chess tree
Move back in the chess tree
Transform the chess tree into PGN
The basic PGN file 1. e4 e5 *
will generated the following chess moments in JSON format:
[
{
"fen": "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"depth": 1,
"index": 0
},
{
"move": "e4",
"fen": "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1",
"depth": 1,
"index": 1
},
{
"move": "e5",
"fen": "rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq e6 0 2",
"depth": 1,
"index": 2
}
]
This package does not support the following features:
- chess symbol annotations
- chess clock comments are removed