You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

pgn-manager

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pgn-manager

Libraray built on top of chess.js and pgn-parser to load and process PGN files in typescript.

2.2.2
latest
Source
npmnpm
Version published
Weekly downloads
83
-41.13%
Maintainers
1
Weekly downloads
 
Created
Source

PGN Manager 📦♟️

A powerful TypeScript/JavaScript library for managing chess PGN (Portable Game Notation) files with support for variations and game traversal.

NPM Package License: MIT TypeScript npm downloads

Features ✨

  • Parse PGN strings into manageable objects
  • Navigate through main lines and variations
  • Access FEN positions for any move
  • Handle game headers
  • Traverse moves forward and backward
  • Full TypeScript support

Installation 🚀

npm install pgn-manager

Usage 💻

import PGNManager from 'pgn-manager';

// Initialize with a PGN string
const pgn = `1. e4 e5 2. Nf3 Nc6 (2... d6 3. d4) 3. Bb5 *`;
const manager = new PGNManager(pgn);

// Get the first move
const firstMove = manager.getFirstMove();

// Navigate through moves
const nextMove = manager.nextMove(firstMove);
const prevMove = manager.previousMove(nextMove);

// Get FEN position for a move
const fen = manager.getMoveFen(firstMove);

// Access game headers
const headers = manager.headers;

API Reference 📚

Constructor

  • new PGNManager(pgn: string): Creates a new PGN manager instance

Properties

  • pgn: Get the raw PGN string
  • parsedPGN: Get the parsed PGN object
  • headers: Get game headers array

Methods

  • getMove(moveNumber: number): Get move by number
  • getMoveNumber(moveOrMoveId: Move | number): Get number for a move
  • nextMove(moveOrMoveId: Move | number): Get next move in the sequence
  • previousMove(moveOrMoveId: Move | number): Get previous move
  • hasNextMove(moveOrMoveId: Move | number): Check if move has a next move
  • getFirstMove(): Get the first move of the game
  • getLastMove(): Get the last move of the game
  • getMoveFen(moveOrMoveId: Move | number): Get FEN position after move
  • getParentRav(moveOrMoveId: Move | number): Get parent variation for move
  • getMoveColor(moveOrMoveId: Move | number): Gets the color of the player who made the move ("w" for white or "b" for black)

Examples 🎯

Traversing Main Line

const manager = new PGNManager("1. e4 e5 2. Nf3 Nc6 3. Bb5 *");
let move = manager.getFirstMove();

while (manager.hasNextMove(move)) {
  console.log(move.move);
  move = manager.nextMove(move);
}

Working with Variations

const manager = new PGNManager("1. e4 e5 2. Nf3 Nc6 (2... d6 3. d4) 3. Bb5 *");
const move = manager.getMove(2); // Get second move
const variation = manager.getParentRav(move);

if (variation) {
  console.log("Move is part of a variation!");
}

Contributing 🤝

Contributions are welcome! Feel free to submit issues and pull requests.

License 📄

MIT License - feel free to use this in your projects!

Keywords

Chess

FAQs

Package last updated on 08 Aug 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.