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

react-pgn-viewer

v2.0.1

Published

React component for creating an interactive PGN viewer from string

Readme

React PGN Viewer

npm version npm Downloads license TypeScript

A modern React component for displaying interactive chess PGN (Portable Game Notation) viewers. Built with React 19, TypeScript, chess.js 1.x, and react-chessboard.

Features

  • 🎯 React 19 functional components with hooks
  • 📝 Full TypeScript support with exported types
  • ♟️ chess.js 1.x for PGN parsing and move validation
  • 🎨 react-chessboard for the chessboard display
  • 📱 Responsive layout with mobile support
  • Dual ESM/CJS output for maximum compatibility
  • 🛡️ Security - XSS prevention with header sanitization

Installation

# Using bun (recommended)
bun add react-pgn-viewer

# Using npm
bun install react-pgn-viewer

# Using yarn
yarn add react-pgn-viewer

Peer Dependencies

{
  "react": "^18.0.0 || ^19.0.0",
  "react-dom": "^18.0.0 || ^19.0.0"
}

Quick Start

import PgnViewer from 'react-pgn-viewer';

function ChessGame() {
  const pgn = `
    [Event "World Chess Championship"]
    [Date "2024.12.12"]
    [White "D. Gukesh"]
    [Black "Ding Liren"]
    [Result "1-0"]

    1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O Be7
    6. Re1 b5 7. Bb3 d6 8. c3 O-O 9. h3 Nb8 10. d4 Nbd7
  `;

  return (
    <PgnViewer blackSquareColor="steelblue" whiteSquareColor="aliceblue" width={600}>
      {pgn}
    </PgnViewer>
  );
}

Props

| Prop | Type | Default | Description | | ------------------ | ----------------------------- | ------------- | -------------------------------------------------- | | children | string | - | PGN string content | | innerHTML | boolean | false | When true, parses <pgn> tags from children | | blackSquareColor | string | "steelblue" | Color of dark squares | | whiteSquareColor | string | "aliceblue" | Color of light squares | | orientation | 'w' \| 'b' | 'w' | Board orientation (white/black at bottom) | | width | number | 600 | Width of the viewer in pixels | | backgroundColor | string | "#e1e5ed" | Background color of the viewer wrapper | | showCoordinates | boolean | true | Show file/rank coordinates on the board | | nodeToModify | string | - | CSS selector for DOM modification (innerHTML mode) | | nodeModification | (node: HTMLElement) => void | - | Callback to modify selected DOM nodes |

TypeScript Types

All types are exported from the package for TypeScript users:

import type {
  PgnViewerProps,
  ViewerProps,
  PgnHeader,
  MoveListProps,
  MoveProps,
  FooterButtonProps,
  BoardStyles,
  StyleParams,
  ResponsiveStyleResult,
} from 'react-pgn-viewer';

Partial Games and FEN Positions

You can display partial games or start from a specific FEN position by adding custom headers to your PGN:

| Header | Description | | ------------------- | ------------------------------------------ | | [StartAtMove "8"] | Skip the first 7 moves and start at move 8 | | [EndAtMove "15"] | Cut off the game after move 15 | | [Fen "..."] | Start from a specific FEN position |

Example: Partial Game

[Event "Example"]
[StartAtMove "4"]
[EndAtMove "8"]

1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 8. c3 O-O

Example: FEN Position

[Event "Example"]
[Fen "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"]

Development

Prerequisites

  • Bun package manager

Getting Started

# Install dependencies
bun install

# Start development server
bun run dev

# Run tests
bun run test:run

# Type check
bun run typecheck

# Build for production
bun run build

# Run tests with coverage
bun run test:coverage

Available Scripts

| Script | Description | | ----------------------- | ------------------------------------------- | | bun run dev | Start Vite dev server | | bun run build | Build library with tsup (ESM + CJS + .d.ts) | | bun run test | Run tests in watch mode | | bun run test:run | Run tests once | | bun run test:coverage | Run tests with coverage report | | bun run typecheck | Run TypeScript type checking | | bun run lint | Run ESLint | | bun run clean | Remove dist and node_modules |

Tech Stack

  • React 19 - UI framework
  • TypeScript 5.7 - Type safety
  • chess.js 1.x - PGN parsing and move generation
  • react-chessboard 4.x - Chess board component
  • tsup - Library bundler (ESM + CJS + .d.ts)
  • Vite - Dev server
  • Vitest - Testing framework
  • Bun - Package manager

Build Output

The library produces three output formats:

dist/
├── index.js      # ESM module
├── index.cjs     # CommonJS module
├── index.d.ts    # TypeScript declarations
└── index.d.cts   # CJS TypeScript declarations

License

MIT © Andrew Gingrich