v1.0.0
A big thank you to all the contributors that helped make this release possible! This is a major version update and there are many new features and breaking changes. Please read below for more info.
Typescript
chess.js has been rewritten in TypeScript. Exported types are as follows:
Chess
classMove
classPiece
Color
Square
PieceSymbol
New Methods
attackers(square, color)
- returns a list of squares occupied by pieces ofcolor
that are attacking the givensquare
getCastlingRights(color)
- returns{ k: boolean, q: boolean }
indicating castling rights forcolor
setCastlingRights(color, rights)
isAttacked(square, color)
- returns true ifsquare
is attacked bycolor
isDrawByFiftyMoves()
moveNumber()
setHeader(key, value)
,removeHeader(key)
,getHeaders()
removeComment()
,removeComments()
Breaking Changes
Exceptions instead of null
The following functions no longer return null
when an error occurs. Instead, they now throw exceptions to provide the user with more detailed error information.
.load()
.loadPgn()
.move()
Chess()
constructor
Function Names
The functions below have been converted to camel-case:
game_over
->isGameOver
in_check
->isCheck
in_checkmate
->isCheckmate
in_draw
->isDraw
is_stalemate
->isStalemate
in_threefold_repetition
->isThreefoldRepetition
insufficient_material
->isInsufficientMaterial
load_pgn
->loadPgn
set_comment
->setComment
get_comment
->getComment
get_comments
->getComments
delete_comment
->deleteComment
delete_comments
->deleteComments
validate_fen
->validateFen
Function Arguments and Return Values
The arguments and return values for the following functions have changed:
load_pgn(pgn, { sloppy: true })
becomesloadPgn(pgn)
(strict
defaults tofalse
)move('Nb7', { sloppy: true })
becomesmoves('Nb7')
clear(true)
should now be written asclear({ preserveHeader: true })
load(fen, true)
should now be written asload(fen, { preserveHeader: true })
validateFen(fen)
now returns{ ok: boolean, error?: string }
Deprecations
- The
flags
field in the Move object is deprecated. Use the new helper methods below to determine the move type:.isCapture()
- is the move a regular capture? NOTE: this isfalse
for an en-passant.isEnPassant()
- is the move an en-passant capture?.isBigPawn()
- is the move a 2-rank pawn move?.isPromotion()
- is the move a pawn promotion?.isKingsideCastle()
- is the move a kingside castle?.isQueensideCastle()
- is the move a queenside castle?
- The
header
function has been deprecated in favor ofsetHeader
andgetHeaders
- The
deleteComment
anddeleteComments
functions have deprecated in favor ofremoveComment
andremoveComments
Improvements
- Change
.load
to throw an exception when loading invalid FEN (@jhlywa - ac977ed ) - Change
.move
to throw an exception on illegal move (@jhlywa - 8523db8) - Change
.loadPgn
to throw an exception when encountered error (@jhlywa - #TODO) - Allow the user to omit castling rights, en passant square, and move numbers when calling
.load
(@jhlywa - 8523db8) - Add
isAttacked
to determine attackers of a specific square (@jhlywa - 9b49454) - Validate king presence in
validateFen
(@jhlywa - a137478) - Allow spaces between the bracket and tag in PGN header (@jhlywa - 5f48a68)
- Allow user to specify a promotion piece (when supplying a verbose move) even if the move is not a promotion (@jhlywa - 8e71084)
- Add
before
andafter
FEN to Move object (@jhlywa - d42b0) - Add removeHeader method (@angarc - #388)
- Fixed moves() when there are no kings (@neofight78 - #386)
- Handle captures with missing ‘x’ (@neofight78 - #385)
- Add methods for getting/setting castling rights (
getCastlingRights
,setCastlingRights
) (@neofight78 - 7cb2d34) - Ensure put/remove functions update ep square (@neofight78 - #398 )
- Make
moveNumber
accessible (@neofight78 - #399) - Add support for both ESM and CommonJS environments (@jorgecasar - #406)
- Add check for invalid pawn placement in validateFen (@Manukyanq - #412)
- Update castling rights and en passant square in
.put()
(@gavin-lb - 55181a9) - Add
skipValidation
option to.load
(@jhlywa - e2ff91c) - Add
isDrawByFiftyMoves
(@HarshilPatel007 - #477) - Add type annotations (@HarshilPatel007 - #478)
Bug Fixes
- Fix
loadPgn()
to handle PGN without any moves (@jhlywa - d12f78f) - Fix
pgn()
export when comment precedes black to move (@jhlywa - 4fd6069) - Remove
postinstall
script (@jhlywa - 495d37) - Add missing
"types": "dist/chess.d.ts"
entry to package.json (@jhlywa - 495d37f) - Fix type of Move.from and Move.to fields (@MichaelTamm - #371)
- Fix major esm inconsistency (@GabrielDelepine - #374)
- Add optional piece argument to .moves() (@ChrisAntley1 - #378)
- Fix README shield links (@JamJomJim - #416)
- Fix three-fold repetition to only return true if the immediate position has been repeated 3 times (@gavin-lb - #144)
- Update internal king cache when overwriting the king via
put()
(@Manukyanq #426) - Always clear Setup and FEN when calling .clear() (@jhlywa - be03fe0)
- Fix positionCount bug when stored in a pinia Vue store (@jhlywa - c1909fe)