Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@chess-fu/fen-parser
Advanced tools
This is a small lightweight chess FEN parser based largely on regex. It unpacks the FEN into discrete properties which can be modified and then turned back into a new FEN via the toString
method.
The following aspects of the FEN are validated:
prnbqk
set.'w'
or 'b'
.'-'
) or contain 'k'
or 'q'
or any file 'abcdefgh'
for Chess960 support.'-'
) or an 'abcdefgh'
file, followed by either 3
or 6
for rank.Due to some irregular FENs in use, the addition case of a missing en passant code followed by 0 0
will be allowed. In this case the FenParser will report as if the ending was - 0 1
and the toString
method will reflect that change. Thank you chess.com for that :D
npm install --save @chess-fu/fen-parser
Not much else to it.
Basic usage:
function () {
assert.isTrue(FenParser.isFen('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'));
assert.isFalse(FenParser.isFen('xxxxx/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'));
const fen = new FenParser('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
assert.isTrue(fen.isValid);
assert.equal(fen.positions, 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR');
assert.equal(fen.ranks[0], 'rnbqkbnr');
assert.equal(fen.ranks[1], 'pppppppp');
assert.equal(fen.ranks[2], '--------');
assert.equal(fen.ranks[3], '--------');
assert.equal(fen.ranks[4], '--------');
assert.equal(fen.ranks[5], '--------');
assert.equal(fen.ranks[6], 'PPPPPPPP');
assert.equal(fen.ranks[7], 'RNBQKBNR');
assert.equal(fen.turn, 'w');
assert.equal(fen.castles, 'KQkq');
assert.equal(fen.enpass, '-');
assert.equal(fen.halfmoveClock, 0);
assert.equal(fen.moveNumber, 1);
assert.equal(fen.toString(), 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
}
static isFen(string): boolean
Returns true if the the parts of the FEN appear valid at a glance. Use the isValid
member to verify run-length encoding.
get isValid: boolean
Returns true if the FEN provided to the constructor was validated and represented the full 8x8 board.
get positions: string
Gets the encoded version of the ranks, use the ranks property to modify.
ranks: string[]
Gets or sets the unencoded rank & file position of pieces using a dash '-'
for an empty square.
turn: 'w' | 'b'
Gets or sets the color of the player who should make the next move.
castles: string
Gets or sets the valid sides (kqKQ
) or files (abcdefghABCDEFGH
) valid for castling.
enpass: string
Gets or sets the currently possible en passant square in file+rank notation, or -
for none.
halfmoveClock: number
Gets or sets the number of halfmoves since the last capture or pawn advance.
moveNumber: number
Gets or sets the number of the full move. It starts at 1, and is incremented after Black's move.
toString(): string
Returns the re-assembled FEN string.
hasPiece(string): boolean
Return true if the piece (character) is found on the board.
counts(): map(string -> number)
Returns a map object for each piece type found to the number of occurrences.
FAQs
Chess FEN parser for 8x8 games, including chess 960
The npm package @chess-fu/fen-parser receives a total of 42 weekly downloads. As such, @chess-fu/fen-parser popularity was classified as not popular.
We found that @chess-fu/fen-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.