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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pech/chess-board

v1.0.2

Published

Chess board UI library — render and interact with chess positions

Readme

chess-board

Chess board UI library — render and interact with chess positions. Supports FEN, drag-and-drop, custom piece/board themes, arrows, last-move and legal-move highlights. Use @pech/chess-core to implement game logic (rules, legal moves, validation).

See: Documentation and examples

Install

npm install @pech/chess-board
# or
bun add @pech/chess-board

Usage

import { ChessBoard, STARTING_FEN } from '@pech/chess-board';

const container = document.getElementById('board')!;
const board = new ChessBoard(container, {
  position: STARTING_FEN,
  orientation: 'white',
  draggable: true,
  onMove(from, to) {
    // Validate with @pech/chess-core and return false to cancel
    return true;
  },
});

// Update position from FEN
board.setPosition('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1');
board.setLastMove('e2', 'e4');
board.setLegalMoves(['e5', 'e6']);
board.setArrows([{ from: 'e2', to: 'e4', color: '#888' }]);
board.destroy();

Options

| Option | Type | Description | |--------|------|-------------| | position | string | Initial FEN (default: starting position). | | orientation | 'white' \| 'black' | Board orientation. | | draggable | boolean | Allow dragging pieces. | | clickable | boolean | Allow square selection/clicks. | | viewOnly | boolean | No drag or selection. | | coordinates | boolean | Show file/rank labels. | | animationDuration | number | Move animation ms. | | pieceTheme | PieceTheme | Function (piece) => SVG string. | | boardTheme | BoardTheme | { lightSquare, darkSquare } colors. | | onMove | (from, to) => boolean \| void | Called on drop; return false to cancel. | | onSelect | (square \| null) => void | Called when selection changes. | | onArrowDrawn | (from, to) => void | Called when user draws arrow (right-drag). |

API

Class

  • ChessBoard — Main class. new ChessBoard(container: HTMLElement, options?: ChessBoardOptions).

FEN

  • STARTING_FEN — Standard starting position FEN string.
  • parseFen(fen: string) — Parse FEN into Map<SquareKey, Piece>.
  • positionToFen(pieces: Map<SquareKey, Piece>) — Build FEN from piece map.

Themes

  • defaultPieceThemePieceTheme using bundled piece SVGs.
  • defaultBoardThemeBoardTheme (green/brown squares).

Types

  • SquareKey, FileChar, RankChar, Color, PieceType, Piece, Arrow, BoardTheme, PieceTheme, ChessBoardOptions.

Board methods

  • Position: setPosition(fen), getPosition().
  • Orientation: setOrientation(color), getOrientation(), flip().
  • Selection: select(square | null).
  • Highlights: setLastMove(from, to), clearLastMove(), setCheck(square | null), setLegalMoves(squares), clearLegalMoves().
  • Arrows: setArrows(arrows), addArrow(from, to, color?), removeArrow(from, to), clearArrows().
  • Lifecycle: destroy().

Implementing the logic with chess-core

We recommend using @pech/chess-core for all game logic: legal moves, move validation, FEN handling, and check/checkmate. Install it and wire it to the board:

npm install @pech/chess-core
# or
bun add @pech/chess-core
import { ChessBoard, STARTING_FEN } from '@pech/chess-board';
import { fromFen, toFen, getLegalMoves, makeMove, fromUci, toUci } from '@pech/chess-core';

const container = document.getElementById('board')!;
let position = fromFen(STARTING_FEN);

const board = new ChessBoard(container, {
  position: STARTING_FEN,
  orientation: 'white',
  draggable: true,
  onMove(from, to) {
    const move = fromUci(position, from + to);
    if (!move) return false;

    const newPos = makeMove(position, move);
    board.setPosition(toFen(newPos));
    board.setLastMove(from, to);
    board.setLegalMoves(getLegalMoves(newPos).map((m) => toUci(m).slice(2, 4)));
    position = newPos;
    return true;
  },
});
board.setLegalMoves(getLegalMoves(position).map((m) => toUci(m).slice(2, 4)));

Docs: chess-core — Getting started & API

Development

bun install          # install dependencies
bun run test         # run tests
bun run test:watch   # run tests in watch mode
bun run build        # build with tsup
bun run typecheck    # type-check without emitting

License

MIT