UNPKG

@lovebowls/leaguejs

Version:

A framework-agnostic JavaScript library for managing leagues, teams, and matches

99 lines (80 loc) 2.1 kB
import { Team } from './Team'; export interface RinkScore { homeScore: number; awayScore: number; } export interface MatchResult { homeScore: number; awayScore: number; winner?: string; isDraw?: boolean; rinkScores?: RinkScore[]; } export interface RinkResults { homeWins: number; awayWins: number; draws: number; total: number; } export interface MatchData { homeTeam: Team | { _id: string; name?: string }; awayTeam: Team | { _id: string; name?: string }; _id?: string; date?: Date | string | null; result?: MatchResult | null; createdAt?: Date; updatedAt?: Date; } export class Match { /** Home team object */ homeTeam: Team; /** Away team object */ awayTeam: Team; /** Date of the match, can be null for unscheduled matches */ date: Date | null; /** Match result, null if not played yet */ result: MatchResult | null; /** Creation date */ createdAt: Date; /** Last update date */ updatedAt: Date; constructor(data: MatchData); /** * The unique identifier for the match (UUID v4 format) */ key: string; /** * Get the name of the home team */ get homeTeamName(): string; /** * Get the name of the away team */ get awayTeamName(): string; /** * Determines the winner of the match based on scores. * @returns The name of the winning team, 'draw', or null if no result is set. */ getWinner(): string | null; /** * Checks if the match resulted in a draw. * @returns True if it's a draw, false otherwise, or null if no result is set. */ isDraw(): boolean | null; /** * Set rink scores for an existing match result * @param rinkScores Array of rink scores * @returns True if scores were set, false if no result exists */ setRinkScores(rinkScores: RinkScore[]): boolean; /** * Get rink win/draw counts * @returns Object with rink win counts or null if no rink scores */ getRinkResults(): RinkResults | null; /** * Convert match to JSON * @returns JSON representation of the match */ toJSON(): object; }