Kokopu
Kokopu is a JavaScript/TypeScript chess library.
It implements the chess game rules, and provides tools to read/write the standard chess file formats
(PGN,
FEN,
UCI,
etc.).

Documentation
https://kokopu.yo35.org/
Installation
- With NPM (or similarly with any package manager for Node.js such as Yarn):
npm install kokopu
- Without a package manager: download the single-file package
kokopu.zip,
unzip it, and include either file kokopu.js or file kokopu.min.js in your HTML page.
Migrate to 3.x and 4.x
Versions 3.0.0 and 4.0.0 introduce some breaking changes with regard to the previous versions.
To determine whether your codebase needs to be adapted or not when upgrading Kokopu,
please look at:
Features
- Chess move generation.
- Check, checkmate and stalemate detection.
- Move legality check.
- Algrebraic notation parsing and generation.
- FEN notation parsing and generation.
- UCI move parsing and generation.
- PGN file parsing and generation (including advanced PGN features
such as commentaries, sub-variations, NAGs,
non-standard starting position...).
- Support several chess variants:
- Chess960, also known as Fischer Random Chess.
- Antichess, also known as losing chess, giveaway chess, suicide chess...
- Horde chess (following Lichess/Chess.com rules).
Kokopu is a headless library, meaning it does not provide any user interface.
If you are interested in UI features (e.g. to be able to render a chessboard component within a web page),
you may take a look at Kokopu-React, which is a React-based library
built on top of Kokopu to provide these kind of features.
Example
const { Position } = require('kokopu');
const position = new Position();
position.play('e4');
position.play('e5');
position.play('Nf3');
console.log(position.ascii({ coordinateVisible: true }));
const moves = position.moves();
console.log(moves.map(move => position.notation(move)));
Or directly within a HTML page, if no package manager is used:
<script src="kokopu.js"></script>
<script>
const position = new kokopu.Position();
position.play('e4');
position.play('e5');
</script>
More examples available in documentation.