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

light-chess

v1.3.2

Published

A simple, fast and light-weight chess library written in Type-Script

Downloads

14

Readme

LIGHT-CHESS By Davi0k

light-chess is a light-weight, simple and fast NodeJS library to handle chess matches and chess moves validation. The library has been written in Type-Script and well documented using TSDoc standard.

Package reference and documentation

You can find the package documentation inside the /docs. This folder contains all the files generated by Typedoc, just open the index.html file and you will be able to explore the documentation as you wish.

Installing the package using NPM

You can install light-chess using the famous package manager NPM. To do so, just type this in your workspace:

npm install light-chess

Now you can import the entire package using commonjs:

const light = require("light-chess");

In Type-Script, you should do:

import light from "light-chess";

A note for Type-Script users

If you are using Type-Script you may want to install the related @types. This step is not required, being light-chess developed entirely in Type-Script, the related @types are automatically installed.

Building the package from source-code

First, clone this repository using git:

git clone https://github.com/Davi0k/light-chess.git
cd light-chess

Then install all the required packages using npm:

npm install

Finally, compile the /src directory using the Type-Script Compiler:

npm run compile

Testing the package

The tests of the project has been written using the Jasmine test-suite. If you want to run them and check the test result, simply run this command:

npm test

Using FEN expressions with light-chess

light-chess supports the import and export of matches in FEN format as well. To import or export a FEN expression, you have to use the apposite method inside the Chess class.

Importing a FEN expression in a match

To do this, you just have to use the Chess.import method:

const chess: Chess = new Chess();

chess.import("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 0");

const chessboard: string = chess.unicode();

console.log(chessboard);

Or you can import the expression directly in the class constructor:

const chess: Chess = new Chess("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 0");

const chessboard: string = chess.unicode();

console.log(chessboard);

Exporting a match into a FEN expression

To do this, you just have to use the Chess.export method:

const chess: Chess = new Chess();

const fen: string = chess.export();

console.log(fen);

A minimal chess game written in Type-Script with light-chess

import { Chess, Coordinate, Movement, Validations } from "light-chess";
import readline from "readline";

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

const chess: Chess = new Chess();

function print(chess: Chess): void {
    console.log(`Current turn: ${chess.turn ? "BLACK" : "WHITE"}`);

    const unicode: string = chess.unicode();

    console.log(unicode + "\n");

    console.log("Insert a valid move: (example: e2 e4)");
}

rl.on("line", function(data: string) {
    const coordinates: [string, string] = data.split(" ") as [string, string];

    const initial: Coordinate = Chess.decode(coordinates[0]), final: Coordinate = Chess.decode(coordinates[1]);

    const movement: Movement = { initial, final };

    const validation: Validations = chess.move(movement);

    switch(validation) {
        case Validations.BLANK_SQUARE:
        case Validations.ILLEGAL_MOVE:
            console.log("Illegal or invalid move for the selected piece\n");
            break;

        case Validations.KING_ON_CHECK:
            console.log("Your king is under attack, this move is illegal\n");
            break;

        case Validations.CHECKMATE:
            console.log(`Checkmate! ${chess.checkmate ? "BLACK" : "WHITE"} wins the match\n`);
            process.exit();
    }

    print(chess);
});

print(chess);

License

This project is released under the GNU General Public License v3.0. You can find the complete license here: https://www.gnu.org/licenses/gpl-3.0.html