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

@echecs/position

v1.0.2

Published

Chess position type and board utilities. Foundation for @echecs/fen, @echecs/san, and @echecs/game.

Readme

Position

npm Test Coverage License: MIT API Docs

Position is a TypeScript library representing a complete chess position — the board, turn, castling rights, en passant square, halfmove clock, and fullmove number — as an immutable value object with a clean query API. It is the foundational package of the ECHECS monorepo. Zero runtime dependencies.

Installation

npm install @echecs/position

Quick Start

import { Position, STARTING_POSITION } from '@echecs/position';

// Starting position
const pos = new Position();

console.log(pos.turn); // 'w'
console.log(pos.fullmoveNumber); // 1
console.log(pos.isCheck); // false

// Query the board
const piece = pos.piece('e1'); // { color: 'w', type: 'k' }
const whites = pos.pieces('w'); // Map<Square, Piece> of all white pieces

// Find all squares a piece occupies
const whiteKing = pos.findPiece({ color: 'w', type: 'k' }); // ['e1']

// Attack queries
const attackers = pos.attackers('e5', 'b'); // squares of black pieces attacking e5
const attacked = pos.isAttacked('f7', 'w'); // true if white attacks f7

API

Full API reference is available at https://mormubis.github.io/position/

Constructor

new Position()
new Position(board: Map<Square, Piece>)
new Position(board: Map<Square, Piece>, options?: {
  castlingRights?: CastlingRights
  enPassantSquare?: Square
  fullmoveNumber?: number
  halfmoveClock?: number
  turn?: Color
})

The no-argument form creates the standard chess starting position. Pass a custom board map and optional options to construct any arbitrary position.

Getters

| Getter | Type | Description | | ------------------------ | --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | | castlingRights | CastlingRights | Which castling moves remain available | | enPassantSquare | Square \| undefined | En passant target square, if any | | fullmoveNumber | number | Fullmove counter (increments after Black's move) | | halfmoveClock | number | Halfmove clock for the fifty-move rule | | hash | string | Zobrist hash string for position identity | | isCheck | boolean | Whether the side to move is in check | | isInsufficientMaterial | boolean | Whether the position is a FIDE draw by insufficient material (K vs K, K+B vs K, K+N vs K, or K+B vs K+B with same-color bishops) | | isValid | boolean | Whether the position is legally reachable | | turn | Color | Side to move ('w' or 'b') |

Methods

attackers(square, color): Square[]

Returns all squares occupied by pieces of color that attack square.

pos.attackers('e5', 'b'); // e.g. ['d7', 'f6']

findPiece(piece): Square[]

Returns all squares occupied by the given piece.

pos.findPiece({ color: 'w', type: 'q' }); // ['d1']

isAttacked(square, color): boolean

Returns true if any piece of color attacks square.

pos.isAttacked('f3', 'w'); // true if white attacks f3

piece(square): Piece | undefined

Returns the piece on square, or undefined if the square is empty.

pos.piece('e1'); // { color: 'w', type: 'k' }
pos.piece('e5'); // undefined (empty in starting position)

pieces(color?): Map<Square, Piece>

Returns a map of all pieces, optionally filtered by color.

pos.pieces(); // all 32 pieces in starting position
pos.pieces('w'); // 16 white pieces

Constants

import {
  COLORS, // ['b', 'w']
  FILES, // ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
  RANKS, // ['1', '2', '3', '4', '5', '6', '7', '8']
  PIECE_TYPES, // ['b', 'k', 'n', 'p', 'q', 'r']
  SQUARES, // all 64 squares, a8–h1 (rank 8 to rank 1)
  EMPTY_BOARD, // empty Map<Square, Piece>
  STARTING_POSITION, // Position instance for the standard starting position
} from '@echecs/position';

Types

All types are exported for use in consuming code and companion packages.

import type {
  CastlingRights, // { bK: boolean; bQ: boolean; wK: boolean; wQ: boolean }
  Color, // 'w' | 'b'
  File, // 'a' | 'b' | ... | 'h'
  Move, // { from: Square; to: Square; promotion: PromotionPieceType | undefined }
  Piece, // { color: Color; type: PieceType }
  PieceType, // 'b' | 'k' | 'n' | 'p' | 'q' | 'r'
  PositionOptions, // options accepted by the Position constructor
  PromotionPieceType, // 'b' | 'n' | 'q' | 'r'
  Rank, // '1' | '2' | ... | '8'
  Square, // 'a1' | 'a2' | ... | 'h8'
  SquareColor, // 'light' | 'dark'
} from '@echecs/position';

Move and PromotionPieceType are exported for use by companion packages (@echecs/san, @echecs/game) that build on this foundational type.