@mainshum/scoreboard v1.0.3
Scoreboard
Set of utilities to track scores for a set of games ⚽️
Api
Game initialization
createNewGame: (home: Team, away: Team, scoreHome?: number, scoreAway?: number) => GameCreates a new
Gameinstance. IfscoreHomeorscoreAwayare not passed, they default to 0.
Instance methods:
incrementHome: () => GameIncrement home team score by 1, returns modified
Gameinstance.incrementAway: () => GameIncrement away team score by 1, returns modified
Gameinstance.totalScore: () => numberHome score + away score
containsTeam: (t: Team) => booleanChecks if team
tis currently playing in this game
Game tracking
createScoreboard: () => ScoreboardFactory method which creates a new scoreboard instance and returns the game
gthat got passed.
Instance methods
startGame: (g: Game) => GameInits new game. If any of the teams is already at play it throws an exception.
gamePending: (g: Game) => booleanCheck if game is on (
gpassed by reference)finishGame: (g: Game) => voidRemove
gfrom the scoreboard (gpassed by reference). If no match found this method does nothing.getSummary: () => Game[]Get a summary of games in progress ordered by their total score. The games with the same total score will be returned ordered by the most recently started match in the scoreboard.
Example
npm i @mainshum/scoreboard
import {createScoreboard, createNewGame} from '@mainshum/scoreboard';
const scoreboard = createScoreboard();
const game = createNewGame('Claude', 'Van Damme');
scoreboard.startGame(game);
game.incrementHome();
game.incrementAway();
console.log(scoreboard.getSummary()[0].gameStats); // { home: { name: 'Claude', score: 1 }, away: { name: 'Van Damme', score: 1 } }