Skip to main content

Installation

Install chessops using your preferred package manager:
npm install chessops

TypeScript configuration

Chessops is built with TypeScript and ships with type definitions. For the best development experience, ensure your tsconfig.json includes:
tsconfig.json
{
  "compilerOptions": {
    "module": "ES2020",
    "moduleResolution": "node",
    "target": "ES2019",
    "lib": ["ES2019"],
    "strict": true,
    "esModuleInterop": true
  }
}
Chessops is an ES module package. If you’re using CommonJS, Node.js will automatically use the CommonJS build from the package exports.

Importing modules

Chessops provides modular imports for different functionality. Import only what you need:

Core types and utilities

import { Chess, Position } from 'chessops/chess';
import { Square, Color, Role, Piece, Move } from 'chessops';
import { SquareSet } from 'chessops';
import { Board } from 'chessops';
import { parseSquare, makeSquare } from 'chessops';

Notation parsers

import { parseFen, makeFen, parseBoardFen } from 'chessops/fen';
import { parseSan, makeSan } from 'chessops/san';
import { parseUci, makeUci } from 'chessops';
import { parsePgn, startingPosition, PgnParser } from 'chessops/pgn';

Attacks and move generation

import {
  attacks,
  ray,
  between,
  kingAttacks,
  knightAttacks,
  pawnAttacks,
  bishopAttacks,
  rookAttacks,
  queenAttacks,
} from 'chessops/attacks';

Chess variants

import { Crazyhouse, Atomic, Antichess, KingOfTheHill } from 'chessops/variant';

Transformations and compatibility

import { flipVertical, flipHorizontal, rotate180 } from 'chessops/transform';
import * as compat from 'chessops/compat';

Verify installation

Create a simple test file to verify the installation:
test.ts
import { Chess } from 'chessops/chess';
import { parseFen } from 'chessops/fen';

const setup = parseFen('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1').unwrap();
const pos = Chess.fromSetup(setup).unwrap();

console.log('Legal moves:', pos.allDests().size);
Run it with:
tsx test.ts
# or with ts-node
ts-node test.ts
You should see Legal moves: 20 printed to the console.

Next steps

Quick start guide

Learn how to use chessops in your application

Build docs developers (and LLMs) love