chess-players
v1.0.3-alpha
Published
Fide Player Download
Downloads
8
Readme
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-playersor
yarn add chess-playersExamples (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}`);
})();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);
})();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);
})();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');
})();