chess-players
TypeScript icon, indicating that this package has built-in type declarations

1.0.3-alpha • Public • Published

The Chess Centre

GitHub CircleCI Coverage Status

Chess Players

Utility for accessing chess player data

GitHub tag (latest by date)

Intro

This NodeJS package is provided to help developers build applications or components which want to use the published chess player rating list data.

An example of this would be a React Component which renders a players profile i.e., name, country, rating - where the component prop accepts the FIDE id from a REST endpoint you expose on your server.

This information is found here at the FIDE website.

Getting started

npm install chess-players

or

yarn add chess-players

Examples (typescript)

Full list

import Fide, { Player } from './fide';
 
(async () => {
  const fide = new Fide();
  const players: Array<Player> = await fide.getPlayers();
 
  console.log(`Players: ${players.length}`);
})();

player count

Top players

import Fide, { Player } from './fide';
 
(async () => {
  const fide = new Fide();
  const players: Array<Player> = await fide.getPlayers();
 
  const topTen = players
    .sort((a: Player, b: Player) => b.rating - a.rating)
    .slice(0, 10)
    .reduce(
      (players: any, player: any) => 
      [...players, { name: player.name, rating: player.rating, nationality: player.country }],
      [],
    );
 
  console.log(topTen);
})();

player top ten

Specific player

import Fide, { Player } from './fide';
 
(async () => {
  const fide = new Fide();
  const players: Array<Player> = await fide.getPlayers();
 
  const player = players.find(player => player.fideid === 418250)
 
  console.log(player);
})();

player top ten

Legacy lists

import Fide, { Player, Options } from './fide';
 
(async () => {
  const fide = new Fide();
  const config: Options = {
    ratingType: "rapid",
    month: "jan",
    year: 2019
  }
  const players: Array<Player> = await fide.getPreviousPlayersList(config);
})();

Memoized (cached API calls)

import Fide from './fide';
 
(async () => {
  const fide = new Fide();
  console.time('players');
  await fide.getPlayers();
  console.timeEnd('players');
 
  console.time('players-memoized');
  await fide.getPlayers();
  console.timeEnd('players-memoized');
})();

player memoized

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i chess-players

Weekly Downloads

1

Version

1.0.3-alpha

License

MIT

Unpacked Size

52.4 kB

Total Files

21

Last publish

Collaborators

  • mdwebb