npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chess-fen

v1.0.2

Published

chess-fen is a library which includes tools for working with Forsyth–Edwards Notation (FEN) in an immutable manner.

Downloads

2,754

Readme

chess-fen

chess-fen is a library which includes tools for working with Forsyth–Edwards Notation (FEN) in an immutable manner.

Installation

npm install chess-fen

Version 1.0.0+

Since 1.0.0 chess-fen is no longer also a standard notation parser and instead focuses on being a simple data structure with basic primitives for working with FEN notation. This means the previous Fen.move() method has been removed along with associated classes, types and functions for working with parsing chess moves.

There have also been some significant changes to the types ( https://github.com/cymantex/chess-fen/blob/master/src/module/types.ts).

Example usage

const emptyPosition = new Fen(Fen.emptyPosition);

//Each update() creates a new Fen instance.
const smotheredMate = emptyPosition
  .update("h8", PIECES.k)
  .update("h7", PIECES.p)
  .update("g7", PIECES.p)
  .update("e8", PIECES.r)
  .update("a8", PIECES.q)
  .update("g5", PIECES.N)
  .update("c4", PIECES.Q)
  .update("h2", PIECES.K);

smotheredMate.printBoard();
// -------------------
// | q . . . r . . k |
// | . . . . . . p p |
// | . . . . . . . . |
// | . . . . . . N . |
// | . . Q . . . . . |
// | . . . . . . . . |
// | . . . . . . . K |
// | . . . . . . . . |
// -------------------

// The original Fen will not be mutated
emptyPosition.printBoard();
// -------------------
// | . . . . . . . . |
// | . . . . . . . . |
// | . . . . . . . . |
// | . . . . . . . . |
// | . . . . . . . . |
// | . . . . . . . . |
// | . . . . . . . . |
// | . . . . . . . . |
// -------------------

API

Constructor: Fen(fenOrArgs?: string | FenArgs)

The constructor takes an optional parameter which specifies the FEN board position.

const startingPosition = new Fen();

console.log(startingPosition.toString());
// rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

console.log(new Fen("rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2").toString());
// rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2

console.log(new Fen(Fen.emptyPosition).toString());
// 8/8/8/8/8/8/8/8 w KQkq - 0 1

get(Coordinate|Position)

Gets the content of the specified position.

const startingPosition = new Fen();

console.log(startingPosition.get("e1"));
// K

console.log(startingPosition.get("e4"));
// empty

console.log(startingPosition.get("k9"));
// null

// You can also send the x and y as a Position.
console.log(startingPosition.get(new Position(4, 7)));
// white king

clear(Coordinate|Position)

Removes the content on the specified position if there is any.

console.log(new Fen().clear("e1").toString());
// "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQ1BNR w KQkq - 0 1"

update(Coordinate|Position, BoardContent)

Replaces the content of the specified position.

console.log(new Fen().update("e1", BoardContent.BlackBishop).toString());
// rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQbBNR w KQkq - 0 1

isOccupied(Coordinate|Position)

const startingPosition = new Fen();

console.log(startingPosition.isOccupied("e2"));
// true

console.log(startingPosition.isOccupied("e4"));
// false

isEmpty(Coordinate|Position)

const startingPosition = new Fen();

console.log(startingPosition.isEmpty("e2"));
// false

console.log(startingPosition.isEmpty("e4"));
// true

Properties

console.log(new Fen(Fen.startingPosition));
// Fen {
//   rows: 8,
//   columns: 8,
//   board: [
//     ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
//     ['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'],
//     [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
//     [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
//     [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
//     [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
//     ['P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'],
//     ['R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R']
//   ],
//   toMove: 'white',
//   castlingRights: {
//     white: { queenside: true, kingside: true },
//     black: { queenside: true, kingside: true }
//   },
//   enPassantSquare: '-',
//   halfMoves: 0,
//   fullMoves: 1
// }