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 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-chessboard

v1.0.6

Published

<div align="center"> <img width="200" align="center"src="https://raw.githubusercontent.com/sockgore/node-chessboard/main/assets/opus.gif"/><br/> <p style="font-size:30px; font-weight:600;margin-top:8px;color:#bfa584;">node-chessboard</p> <p

Downloads

62

Readme

Overview

Generate a Buffer with a provided PGN or FEN with full customisability. Intended to work alongside chess.js.

Documentation

Installation

Install via node:

npm install node-chessboard

Import the package and instantiate a new Chessboard.

import { Chessboard } from "node-chessboard";

const chessboard = new Chessboard();

You may also pass in options for customisability.

import { Chessboard, Theme } from "node-chessboard";

const chessboard = new Chessboard({
	size: 720,
	light: "rgb(240, 217, 181)"
	dark: "rgb(181, 136, 99)",
	highlight: "rgba(235, 97, 80, 0.8)"
});

Load in your chess positions with any of the provided methods and export as a Buffer.

Supported Formats

Loading by FEN

.loadFEN(fen)

|Parameter|Type|Description| |-|-|-| |fen|string|If you are using chess.js, you can retrieve the FEN value with Chess.fen()|

FEN appears in the following format:

// 8/8/8/8/8/8/8/8 w - - 0 1

Loading by PGN

.loadPGN(pgn)

|Parameter|Type|Description| |-|-|-| |pgn|string|If you are using chess.js, you can retrieve the PGN value with Chess.pgn()|

PGN appears in the following format:

1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 {This opening is called the Ruy Lopez.}
4. Ba4 Nf6 5. O-O Be7 6. Re1 b5 7. Bb3 d6 8. c3 O-O 9. h3 Nb8 10. d4 Nbd7
11. c4 c6 12. cxb5 axb5 13. Nc3 Bb7 14. Bg5 b4 15. Nb1 h6 16. Bh4 c5 17. dxe5
Nxe4 18. Bxe7 Qxe7 19. exd6 Qf6 20. Nbd2 Nxd6 21. Nc4 Nxc4 22. Bxc4 Nb6
23. Ne5 Rae8 24. Bxf7+ Rxf7 25. Nxf7 Rxe1+ 26. Qxe1 Kxf7 27. Qe3 Qg5 28. Qxg5
hxg5 29. b3 Ke6 30. a3 Kd6 31. axb4 cxb4 32. Ra5 Nd5 33. f3 Bc8 34. Kf2 Bf5
35. Ra7 g6 36. Ra6+ Kc5 37. Ke1 Nf4 38. g3 Nxh3 39. Kd2 Kb5 40. Rd6 Kc5 41. Ra6
Nf2 42. g4 Bd3 43. Re6 1/2-1/2

Generating a Buffer

After you've loaded a chess position, you can use .buffer() to generate a buffer.

|Parameter|Type|Description| |-|-|-| |mime|string|A string that specifies the MIME type of the image. Only accepts image/png, image/jpeg, image/webp, image/avif and image/gif| |options|BufferOptions?|The buffer options. See the BufferOptions interface below for detailed information.

BufferOptions

|Property|Type|Description| |-|-|-| |delay|number?|Sets the delay between each frame, 500 by default. Only applicable if mime is image/gif| |move|number?|Specifies the move number in a PGN string to which the game should be played up to. For example:| |||- If move is 2, and the PGN string loaded is "1. Nc3 Nf6 2. Ne4", the result should be "1. Nc3 Nf6"| |||- Alternatively, if move is 1, the result should be "1. Nc3"|

Example

This is an example of loading a gif and png Buffer for a game that had Fool's Mate.

import { Chessboard } from "node-chessboard";

const chessboard = new Chessboard();
// Loading Fool's Mate
chessboard.loadPGN("1. e4 g5 2. Nc3 f5 3. Qh5#");
chessboard.buffer("image/gif").then(buffer => fs.writeFile("assets/game.gif", buffer));

// Getting the 4th move
chessboard.buffer("image/png", { move: 4, highlight: true }).then(buffer => fs.writeFile("assets/blunder.png", buffer));

These are the gif and png output respectively:

Dependencies