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

fast-pgn-parser

v0.1.1

Published

Basic but fast PGN parser

Readme

fast-pgn-parser

Basic but fast PGN (Portable Game Notation) parser for Node.js, backed by C bindings to libpgn.

The core parsing is implemented in C via libpgn and exposed to Node.js through native bindings.

Status

In development. N-API bindings to libpgn are in place: libpgn is built and statically linked into the native addon. If the addon fails to build (no git, no C++ toolchain), the module throws at load time.

API

  • parse(pgnText) — Parses PGN text and returns an array of game objects. Each game has:
    • tags — Object of key/value PGN headers (e.g. Event, White, Black, Result).
    • moves — Array of move strings (SAN notation).
    • pgntext — the raw PGN text for that game only.

Example:

import { parse } from 'fast-pgn-parser';

const games = parse(pgnText);
for (const game of games) {
  console.log(game.tags.Event, game.tags.White, 'vs', game.tags.Black);
  console.log(game.moves);  // ['e4', 'e5', 'Nf3', ...]
  console.log(game.pgntext); // is the unparsed PGN for this game
}

Project layout

  • src/ — Node.js API and N-API addon (binding.cc)
  • test/ — Tests (node --test)
  • vendor/libpgn is cloned into vendor/libpgn on install (see vendor/README.md)

Scripts

  • npm install — install deps, clone libpgn if needed, build native addon (fails if addon cannot be built)
  • npm run rebuild — rebuild the native addon (node-gyp)
  • npm test — run tests
  • npm run test:coverage — run tests with coverage (c8)
  • npm run benchmark — benchmark parse() vs pgn-parser using scripts/games.pgn (default 100 runs; node scripts/benchmark-parse.mjs [path] [N])

Building the native addon

  • Node.js ≥ 18
  • Git — to clone libpgn (or add vendor/libpgn manually)
  • C/C++ toolchainnode-gyp (e.g. Visual Studio Build Tools on Windows, Xcode CLI on macOS, build-essential on Linux)

On Windows, Visual Studio 18 (version 18 in the install path) is supported via a postinstall script (scripts/fix-node-gyp-vs18.cjs) that applies the same approach as projects like bitboard-chess: node-gyp is adjusted so version 18 is treated as 2022 and the v145 toolset is used when the path contains \18\. No patch file is used.

After npm install, the addon is in build/Release/pgn_parser.node. If the addon did not build, importing the module throws.