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

inner-chess

v2.4.4

Published

A nodeJS package that utilises the internal API for chess.com, allowing for live-updating information.

Downloads

14

Readme

Inner-chess

A nodeJS package that utilises the internal API for chess.com, allowing for verbose live-updating information.

Features:

  • Free game review

  • Search for a user

  • Fetch user's information

  • Fetch user's past games

  • Fetch user's live/ongoing games

  • Fetch user's variants stats

  • Fetch user's status

Benefits:

  • Supports variants

  • Information is updated real-time with the chess.com servers (as opposed to every x time frame with the public API)

TODO:

Additions:

  • [x] ~~Add get user's friends~~ DONE

  • [x] ~~Add get user's achievements~~ DONE

  • [ ] Add fetching leader-boards

  • [ ] Add support for clubs

  • [ ] Add support for leagues

  • [ ] Add game fetching for variants

Bug fixes:

  • [ ] Fix unable to view some live games issue

  • [x] ~~Speed up achievements for players with large numbers of them~~ DONE

Simple usage:

const { Chess } = require("inner-chess");

let chess = new Chess();

chess.Search("some-user").then(async  users  =>{
	let user = users[0];

	let profile = await  chess.User(user.username);
	console.log(profile);

	let stats = await  chess.Stats(user.username);
	console.log(stats);
})

Documentation:

Uncredentialed endpoints:

Achievements(username)

Params:

username - string (The Chess.com username)

Description:

Gets a list of a user's achievements.

See Returns

Usage:

const { Chess } = require("inner-chess");

let chess = new Chess();

chess.Achievements('some-user', true).then(liveGames  => {
	console.log(liveGames);
})

DecodeMoves(moveList)

Params:

moveList - string (The string provided by chess.Game())

Description:

Decodes the moveList provided by chess.Game()

See Returns

Usage:

const { Chess } = require("inner-chess");

let chess = new Chess();

chess.Games('some-user').then(async  games  => {
	let  chosenGame = games[0];
	
	let  game = await  chess.Game(chosenGame.id);
	
	let  moves = chess.DecodeMoves(game.game.moveList);
	console.log(moves);
})

Game(gameId, type)

Params:

gameId - string/int (The ID provided by chess.Games())

type - string (Can be one of Chess.GAMES)

Description:

Gets information on a game from chess.Games()

See Returns

Usage:

const { Chess } = require("inner-chess");

let chess = new Chess();

chess.Games('some-user').then(async  games  => {
	let  chosenGame = games[0];

	let  game = await  chess.Game(chosenGame.id);
	console.log(game);
})

Games(username, live)

Params:

username - string (The Chess.com username)

live - boolean (Whether to look for user's live games. [Can be used to get a user's status])

Description:

Gets a list of recent games played by user.

See Returns

See Returns - Live Games

Usage:

const { Chess } = require("inner-chess");

let chess = new Chess();

chess.Games('some-user').then(games  => {
	console.log(games);
})

chess.Games('some-user', true).then(liveGames  => {
	console.log(liveGames);
})

Search(username, live)

Params:

username - string (The Chess.com username)

Description:

Gets a list of users that match the username query.

See Returns

Usage:

const { Chess } = require("inner-chess");

let chess = new Chess();

chess.Search('some-username').then(users  => {
	console.log(users);
})

Stats(username)

Params:

username - string (The Chess.com username)

Description:

Gets the specified user's standard chess statistics.

See Returns

Usage:

const { Chess } = require("inner-chess");

let chess = new Chess();

chess.Stats('some-user').then(stats  => {
	console.log(stats);
})

User(username)

Params:

username - string (The Chess.com username)

Description:

Gets the specified user's profile information.

See Returns

Usage:

const { Chess } = require("inner-chess");

let chess = new Chess();

chess.User('some-user').then(user  => {
	console.log(user);
})

Credentialed Endpoints:

An introduction.

Credentialed endpoints are different to the first section of this package. This is for two reasons:

  1. They require credentials to access the data

  2. There are technical differences between accessing each type of data

Rest assured, accessing credentialed data can be done.

However, it requires user authentication (email + password + username).

It is relatively simple to get credentialed endpoints working.

But before that, I recommend you to go through the package and check that your information is not stored or transferred in any way before providing it with any personal information.

The only time your data is used is here, to log on and get your PHPSESSID cookie.

Initialisation:

Here is some boilerplate code for initialising the variant side of the package:

const { Chess } = require("inner-chess");

(async () => {
	//Initialise the variant manager
	let chess = new Chess()

	await chess.Init();
})()

There are two ways to provide the package with your email, username and password:

  1. (Recommended) Make use of environment variables and set them as EMAIL, USERNAME and PASSWORD respectively. See here

  2. Pass them to the Chess constructor directly:

const { Chess } = require("inner-chess");

(async () =>{
	//Initialise the variant manager
	let chess = new Chess('some-email', 'some-password', 'some-username');

	await chess.Init();
})()

This may take some time to perform as it uses puppeteer, although it will only need to be performed once, or every few hours depending on how often the variant manager is used (It is all handled internally, so do not worry about re-initialising your Variant manager).

Optionally you do not have to run chess.Init() as if a credentialed function is ran, it will automatically initialise it. However this adds time to the function call, so it is recommended that you initialise before the package is used.

Evaluate(moveList)

Params:

moveList - string (The Chess.com game moveList)

Description:

Gets the specified user's friends.

See Returns

Usage:

const { Chess } = require("inner-chess");

(async () => {
	//Initialise the variant manager
	let chess = new Chess('some-email', 'some-password', 'some-user')//Or use environment variables

	let games = await chess.Games("some-user");
	let game = await chess.Game(games[0].id);

	await chess.Init();

	let evaluation = await chess.Evaluate(game.game.moveList)
	console.log(evaluation);
})()

Friends(username)

Params:

username - string (The Chess.com username)

pages - integer (Number of pages of friends to get, defaults to Infinity)

avatarSize - integer (Size of returned friends' avatars, defaults to 64)

Description:

Gets the specified user's friends.

See Returns

Usage:

const { Chess } = require("inner-chess");

(async () => {
	//Initialise the variant manager
	let chess = new Chess('some-email', 'some-password', 'some-user')//Or use environment variables

	await chess.Init();

	let friends = await chess.Friends('some-user')
	console.log(friends);
})()

VariantStats(username)

Not to be confused with chess.Stats()

Params:

username - string (The Chess.com username)

Description:

Gets the specified user's variant stats.

See Returns

Usage:

const { Chess } = require("inner-chess");

(async () => {
	//Initialise the variant manager
	let chess = new Chess('some-email', 'some-password', 'some-user')//Or use environment variables

	await chess.Init();

	let stats = await chess.VariantStats('some-user')
	console.log(stats);
})()

Constants

Chess.GAMES:

  • LIVE - A live game

  • COMPUTER - A computer game

  • BOT - Alias for computer

  • DAILY - A daily game

Credits

Coded by ProfessorFish

If you find any bugs or issues or just need help, then click on the link above and join the Discord server where you will be able to ask me for help.