Home

Awesome

worldcup.js

A JavaScript API client for worldcupjson.net.


Installation

# with npm
npm install worldcup.js

# with yarn
yarn add worldcup.js

Usage

// cjs
const { Client } = require('worldcup.js');
const client = new Client();

// esm
import WorldCup from 'worldcup.js';
const client = new WorldCup.Client();

worldcup.js uses a Client/Manager/Cache system with the ability to fetch teams, groups, matches, and detailed match information from the API.

worldcup.js also has an ID system, where the .id of any object is a unique string value across all objects. This can be passed into a manager to re-fetch the data or store relations. For example, to fetch the specific team with the ID team_USA, I could call client.teams.fetch('team_USA').

Managers

Managers extending from the Manager exist for matches, teams, and groups entitled MatchManager, TeamManager, and GroupManager respectively. Calling the fetch() method on any Manager will fetch all when given no parameters, fetch an ID when passed an ID, and sort when passed in an object with sorting critera. These functions return a collection of Teams, Groups, or Matches.

Collections

A Collection is an ordered key/value pair built off of the Map class. Managers will return a collection of items when fetching as well as when storing cached items.

Ratelimits

This package implements ratelimiting at 5 requests per 30 seconds (the API itself has a limit of 10 per 60 seconds).

Detailed requests

Detailed requests are any requests made directly to an object (like fetching a specific team or match) or any fetch with the option detailed set to true.

Some examples:

Get matches today

console.log(await client.matches.fetch({ dateRange: 'today' })); // -> Collection<id, Match>

Load API data into cache

await client.load();
console.log(client.cache.matches); // -> Collection<id, Match>
console.log(client.cache.teams); // -> Collection<id, Team>
console.log(client.cache.groups); // -> Collection<id, Group>

Get all teams as an array

const teams = await client.teams.fetch();
console.log(teams.toArray()); // -> [ Team, Team, ... ]

Reference

Match

Properties:

Group

Properties:

Team

Properties:

MatchTime

Properties:

MatchWeather

Properties: