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

@knights-eye-chess/game-tree

v0.1.0-dev.8

Published

Private optional structural chess tree and PGN preview

Readme

Knight's Eye Game Tree

Store a chess game as a tree of legal moves, including nested variations, comments and annotations. Import PGN, navigate a line, promote a variation and export PGN again without losing the history that led to each move.

Game Tree is useful for study editors, game viewers and analysis apps. It uses chess.js for legality; your app supplies the interface and decides how to save games.

What you can build

  • A PGN viewer that follows the main line or explores variations.
  • A study editor with branch promotion, deletion and move comments.
  • A game model that keeps repeated positions and transpositions as separate occurrences.
  • A structural snapshot for your own storage or board component.

Get started

Use Node 24 or newer. This is a preview package; npm publication has not been performed. From a checkout of this repository:

npm ci
npm run pack:checked

The command builds, tests and writes a versioned .tgz in artifacts/. Install that archive in your app:

npm install /absolute/path/to/game-tree/artifacts/knights-eye-chess-game-tree-0.1.0-dev.6.tgz

Parse a game, inspect an occurrence and export its variations:

import { parsePgnTree, exportPgnTree } from '@knights-eye-chess/game-tree/pgn';
import { primaryLineEdges, treeOccurrence } from '@knights-eye-chess/game-tree/tree';

const { gameTree, headers } = parsePgnTree('1. e4 e5 (1... c5) 2. Nf3 *');
const secondMove = primaryLineEdges(gameTree)[1];
console.log(treeOccurrence(gameTree, secondMove.childId));
// { rootFen: ..., moves: ['e2e4', 'e7e5'] }
console.log(exportPgnTree(gameTree, headers));

Edit and navigate

Create a tree and append legal UCI moves:

import { createGameStructure, appendGameStructureMove,
  primaryLineEdges } from '@knights-eye-chess/game-tree/tree';

const tree = createGameStructure();
const e4 = appendGameStructureMove(tree, tree.rootId,
  { uci: 'e2e4', comments: ['Control the centre'] }, { primary: true });
appendGameStructureMove(tree, e4.childId, { uci: 'e7e5' }, { primary: true });
console.log(primaryLineEdges(tree).map(edge => edge.san)); // ['e4', 'e5']

promoteTreeEdge(tree, edgeId) chooses the main continuation at that branch. deleteTreeEdge(tree, edgeId) removes its subtree. pathEdgesToNode returns a node's ordered history. Occurrences use the root FEN and full move path, so equal board positions never merge different histories.

API and limits

| Entry point | Purpose | | --- | --- | | @knights-eye-chess/game-tree/tree | Create, edit, navigate and detach structural snapshots. | | @knights-eye-chess/game-tree/pgn | parsePgnTree and exportPgnTree. | | @knights-eye-chess/game-tree/contracts | Structure types and GAME_TREE_VERSION. |

There is no root import. See tree APIs, PGN APIs and examples in tests.

PGN support includes legal nested variations, edge comments, symbolic annotations, numeric NAGs and custom FEN roots. It normalizes formatting. Root/pre-move comments, root NAGs and unknown PGN extensions are not represented. Export uses headers.Result or * unless you supply a result; it does not infer the winner.

Snapshots include structural data. Your app owns analysis, classifications, transient branches and persistence. The package's runtime dependency is chess.js 1.4.0; it does not need an engine or a board UI.

Development

npm ci
npm run check
npm run pack:checked

Edit the source in this repository. SOURCE-ORIGIN.json records the historical extraction; current builds do not require the old application checkout. Tests cover legal replay, variations, special moves and occurrence identity.

See npm publishing for release preparation.

License

First-party code is MIT. See licensing details and third-party notices.