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

backgammon-board-react

v2.0.0

Published

Simplistic backgammon board in react

Readme

backgammon-board-react

A React component library for rendering a backgammon board. Displays positions, dice, and the doubling cube as a scalable SVG. Fully typed with TypeScript.

Use the online editor:https://backgammonist.github.io/backgammon-board-react/

Installation

npm install backgammon-board-react
# or
pnpm add backgammon-board-react
# or
yarn add backgammon-board-react

Peer dependencies — make sure these are already in your project:

npm install react react-dom

Supports React 17, 18, and 19.

Quick start

import { Backgammon } from "backgammon-board-react";

export default function App() {
  return (
    <Backgammon
      positions={[
        { position: 1, playerType: "opponent", numberOfCheckers: 2 },
        { position: 6, playerType: "player", numberOfCheckers: 5 },
        { position: 8, playerType: "player", numberOfCheckers: 3 },
        { position: 12, playerType: "opponent", numberOfCheckers: 5 },
        { position: 13, playerType: "player", numberOfCheckers: 5 },
        { position: 17, playerType: "opponent", numberOfCheckers: 3 },
        { position: 19, playerType: "opponent", numberOfCheckers: 5 },
        { position: 24, playerType: "player", numberOfCheckers: 2 },
      ]}
      dice={[3, 5]}
    />
  );
}

Board layout

Positions follow the standard backgammon numbering from the player's perspective:

  13 14 15 16 17 18 | BAR | 19 20 21 22 23 24
  ──────────────────────────────────────────
  12 11 10  9  8  7 |     |  6  5  4  3  2  1
  • 1–24 — points on the board
  • 0 — player's home/off (checkers borne off by player)
  • 25 — opponent's home/off (checkers borne off by opponent)
  • "bar" — the centre bar; both players can have checkers here

Props

<Backgammon>

| Prop | Type | Default | Description | | -------------- | ------------------------------------------ | ------------- | ---------------------------------------------------- | | positions | Position[] | [] | Checker placement on the board | | dice | [DieValue, DieValue] \| [DieValue] \| [] | [] | Dice to display (1–6 each) | | doublingCube | DoublingCube | — | Doubling cube state | | direction | 'clockwise' \| 'anticlockwise' | 'clockwise' | Direction the player moves checkers around the board | | preset | 'default' \| 'warm' | 'default' | Built-in colour theme | | theme | Theme | — | Custom colour theme (overrides preset) |

Position

type Position = {
  playerType:       'player' | 'opponent';
  position:         0 | 1 | 2 | ... | 24 | 25 | 'bar';
  numberOfCheckers: 1 | 2 | ... | 15;
};

DoublingCube

type DoublingCube = {
  value: 2 | 4 | 8 | 16 | 32;
  owner?: "player" | "opponent" | null; // null = centre (unclaimed)
};

Theme

type Theme = {
  backgroundColor: string;
  borderColor: string;
  pointColor: string;
  pointNumberColor: string;
  altPointColor: string;
  playerCheckerColor: string;
  playerCheckerBorderColor: string;
  opponentCheckerColor: string;
  opponentCheckerBorderColor: string;
  doublingCubeColor: string;
};

Examples

Using a built-in theme preset

<Backgammon preset="warm" positions={positions} dice={[6, 6]} />

Available presets: 'default' (light tan, teal points) and 'warm' (burlap, dark red points).

Custom theme

<Backgammon
  positions={positions}
  theme={{
    backgroundColor: "#1a1a2e",
    borderColor: "#16213e",
    pointColor: "#0f3460",
    pointNumberColor: "#e94560",
    altPointColor: "#533483",
    playerCheckerColor: "#e94560",
    playerCheckerBorderColor: "#ffffff",
    opponentCheckerColor: "#ffffff",
    opponentCheckerBorderColor: "#e94560",
    doublingCubeColor: "#e94560",
  }}
/>

Checkers on the bar

<Backgammon
  positions={[
    { position: "bar", playerType: "player", numberOfCheckers: 1 },
    { position: "bar", playerType: "opponent", numberOfCheckers: 2 },
  ]}
/>

Borne-off checkers

Use position 0 for the player and 25 for the opponent:

<Backgammon
  positions={[
    { position: 0, playerType: "player", numberOfCheckers: 3 },
    { position: 25, playerType: "opponent", numberOfCheckers: 1 },
  ]}
/>

Doubling cube

<Backgammon
  positions={positions}
  doublingCube={{ value: 4, owner: "player" }}
/>

Controlled game state

The component is intentionally stateless — it renders whatever you pass as props. Wire it to your own state or game engine:

import { useState } from "react";
import { Backgammon } from "backgammon-board-react";
import type { Position } from "backgammon-board-react";

const INITIAL_POSITIONS: Position[] = [
  { position: 1, playerType: "opponent", numberOfCheckers: 2 },
  { position: 6, playerType: "player", numberOfCheckers: 5 },
  { position: 8, playerType: "player", numberOfCheckers: 3 },
  { position: 12, playerType: "opponent", numberOfCheckers: 5 },
  { position: 13, playerType: "player", numberOfCheckers: 5 },
  { position: 17, playerType: "opponent", numberOfCheckers: 3 },
  { position: 19, playerType: "opponent", numberOfCheckers: 5 },
  { position: 24, playerType: "player", numberOfCheckers: 2 },
];

export default function Game() {
  const [positions, setPositions] = useState(INITIAL_POSITIONS);
  const [dice, setDice] = useState<[number, number]>([1, 1]);

  const roll = () =>
    setDice([Math.ceil(Math.random() * 6), Math.ceil(Math.random() * 6)] as [
      number,
      number,
    ]);

  return (
    <>
      <Backgammon positions={positions} dice={dice} />
      <button onClick={roll}>Roll</button>
    </>
  );
}

Next.js

The package ships with a 'use client' directive banner. You can import it directly inside a Client Component without any additional configuration:

// app/game/page.tsx
"use client";

import { Backgammon } from "backgammon-board-react";

export default function GamePage() {
  return <Backgammon preset="default" />;
}

TypeScript

All types are exported from the package entry point:

import type {
  Position,
  PlayerType,
  DieValue,
  DoublingCube,
  Direction,
  Theme,
} from "backgammon-board-react";

License

MIT