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

fischer960

v1.0.0

Published

Fischer Random Chess / Chess960 library

Downloads

17

Readme

Fischer960

A Fischer Random Chess / Chess960 JavaScript library based on algorithms.

let sp = fischer.random()

sp.id // -> 518
sp.arrangement // -> ['R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R']

Install

npm: npm i fischer960
yarn: yarn add fischer960
pnpm: pnpm add fischer960

Use

One can import only the functions to be used:

import { random, toString, toUnicode } from 'fischer960'

But importing the whole library will let you write fischer.random() 😎

import * as fischer from 'fischer960'
let sp = fischer.random()

A few things to be aware of:

  • IDs are zero-indexed (0-959, the standard starting position being 518)
  • random() and decode() return the arrangement as an array (to convert the array to a string, see toString())
  • All arrangement arguments can take either an array (['B', 'B', 'Q', 'N', 'N', 'R', 'K', 'R']) or a string ('BBQNNRKR')

Main functions

random()

Generates a random starting position, returning its ID and arrangement of pieces.

random() // -> eg. { id: 518, arrangement: ['R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'] }

randomID()

Picks a random starting position's ID.

randomID() // -> eg. 518

decode(id)

Given an ID, returns the starting position's arrangement of pieces, or false if the ID is invalid.

decode(518) // -> eg. ['R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R']

encode(arrangement)

Given an arrangement of pieces, returns the starting position's ID, or -1 if the arrangement is invalid.

encode('RKRNNQBB') // -> 959

Helper functions

A set of helper functions for manipulating arrangements are also provided.

Except for toString() and toArray(), these functions return the same type as was provided (if you pass a string you get a string, if you pass an array you get an array). Except for toLowerCase() and toUpperCase(), these also return the same case as was provided.

toString(arrangement)

Converts an arrangement of pieces from Array to String.

toString(['B', 'B', 'Q', 'N', 'N', 'R', 'K', 'R']) // -> 'BBQNNRKR'

toArray(arrangement)

Converts an arrangement of pieces from String to Array.

toArray('BBQNNRKR') // -> ['B', 'B', 'Q', 'N', 'N', 'R', 'K', 'R']

toLowerCase(arrangement)

Converts an arrangement of pieces to lowercase notation.

toLowerCase('BBQNNRKR') // -> 'bbqnnrkr'

toUpperCase(arrangement)

Converts an arrangement of pieces to uppercase notation.

toUpperCase('bbqnnrkr') // -> 'BBQNNRKR'

toMirror(arrangement)

Mirrors an arrangement of pieces (returns its “twin”).

toMirror('BBQNNRKR') // -> 'RKRNNQBB'

toUnicode(arrangement, color)

Converts an arrangement of pieces to Unicode symbols.

The color argument is optional and defaults to white (falsy = white, truthy = black).

Note: There's no way to convert back to letters from Unicode symbols.

toUnicode('BBQNNRKR') // -> '♗♗♕♘♘♖♔♖'
toUnicode('BBQNNRKR', true) // -> '♝♝♛♞♞♜♚♜'

isValidArrangement(arrangement)

Validates a starting position's arrangement of pieces.

isValidArrangement('BBQNNRKR') // -> true
isValidArrangement('KQRBRBNN') // -> false (not a valid starting position)

isValidID(id)

Validates a starting position's ID.

Note: 960 is not a valid ID, as this library uses zero-based IDs.

isValidID(0) // -> true
isValidID(960) // -> false