This NodeJS package is provided to help developers quickly build applications or components which want to use the published FIDE chess player rating list data.
An example of this would be a React
component which renders a players profile name
country
rating
where you would expose this data on your backend server, via a REST
or GraphQL
API.
This might look something like this:
import React, { useEffect, useState } from 'react';
export default const PlayerProfile = props => {
const { id as FIDE_ID } = props;
const [player, updatePlayer] = useState({});
const getPlayer = async () => updatePlayer(() => { ...await fetch(`/player/${FIDE_ID}`));
useEffect(() => await getPlayer(), []);
return (<div>
<h1>Fide Profile</h1>
<div>Name: {player.name}</div>
<div>Rating: {player.rating}</div>
<div>Country: {player.country}</div>
</div>);
}
// App.js -> <PlayerProfile id="123456" />
npm install chess-players
or
yarn add chess-players
import Fide, { Player } from './fide';
(async () => {
const fide = new Fide();
const players: Array<Player> = await fide.getPlayers();
console.log(`Players: ${players.length}`); // OR res.send();
})();
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); // OR res.send();
})();
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); // OR res.send();
})();
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);
})();
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');
})();