
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
pgn-manager
Advanced tools
Libraray built on top of chess.js and pgn-parser to load and process PGN files in typescript.
A powerful TypeScript/JavaScript library for managing chess PGN (Portable Game Notation) files with support for variations and game traversal.
npm install pgn-manager
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;
new PGNManager(pgn: string)
: Creates a new PGN manager instancepgn
: Get the raw PGN stringparsedPGN
: Get the parsed PGN objectheaders
: Get game headers arraygetMove(moveNumber: number)
: Get move by numbergetMoveNumber(moveOrMoveId: Move | number)
: Get number for a movenextMove(moveOrMoveId: Move | number)
: Get next move in the sequencepreviousMove(moveOrMoveId: Move | number)
: Get previous movehasNextMove(moveOrMoveId: Move | number)
: Check if move has a next movegetFirstMove()
: Get the first move of the gamegetLastMove()
: Get the last move of the gamegetMoveFen(moveOrMoveId: Move | number)
: Get FEN position after movegetParentRav(moveOrMoveId: Move | number)
: Get parent variation for movegetMoveColor(moveOrMoveId: Move | number)
: Gets the color of the player who made the move ("w" for white or "b" for black)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);
}
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!");
}
Contributions are welcome! Feel free to submit issues and pull requests.
MIT License - feel free to use this in your projects!
FAQs
Libraray built on top of chess.js and pgn-parser to load and process PGN files in typescript.
The npm package pgn-manager receives a total of 83 weekly downloads. As such, pgn-manager popularity was classified as not popular.
We found that pgn-manager demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.