@lovebowls/leaguejs
Version:
A framework-agnostic JavaScript library for managing leagues, teams, and matches
149 lines (148 loc) • 6.07 kB
TypeScript
export class League {
/**
* Create a League instance from JSON data
* @param {Object|string} jsonData - League data as JSON object or string
* @returns {League} - New League instance
*/
static fromJSON(jsonData: Object | string): League;
/**
* Create a new League
* @param {Object} data - League data
* @param {string} [data._id] - Unique identifier for the league (auto-generated if not provided)
* @param {string} data.name - Name of the league
* @param {Object} [data.settings] - League settings
* @param {number} [data.settings.pointsForWin=3] - Points awarded for a win
* @param {number} [data.settings.pointsForDraw=1] - Points awarded for a draw
* @param {number} [data.settings.pointsForLoss=0] - Points awarded for a loss
* @param {number} [data.settings.promotionPositions] - Number of teams that get promoted
* @param {number} [data.settings.relegationPositions] - Number of teams that get relegated
* @param {number} [data.settings.timesTeamsPlayOther=2] - Number of times teams play against each other (1-10)
* @param {number} [data.settings.maxRinksPerSession] - Maximum number of rinks available per session
* @param {Object} [data.settings.rinkPoints] - Settings for rink-based scoring
* @param {number} [data.settings.rinkPoints.pointsPerRinkWin=2] - Points awarded per winning rink
* @param {number} [data.settings.rinkPoints.pointsPerRinkDraw=1] - Points awarded per drawn rink
* @param {number} [data.settings.rinkPoints.defaultRinks=4] - Default number of rinks per match
* @param {boolean} [data.settings.rinkPoints.enabled=false] - Whether rink points are enabled
* @param {Array<Team>} [data.teams=[]] - Initial list of teams
* @param {Array<>} [data.matches=[]] - Initial list of matches
* @param {Date} [data.createdAt] - Creation date (defaults to current date)
* @param {Date} [data.updatedAt] - Last update date (defaults to current date)
*/
constructor(data: {
_id?: string | undefined;
name: string;
settings?: {
pointsForWin?: number | undefined;
pointsForDraw?: number | undefined;
pointsForLoss?: number | undefined;
promotionPositions?: number | undefined;
relegationPositions?: number | undefined;
timesTeamsPlayOther?: number | undefined;
maxRinksPerSession?: number | undefined;
rinkPoints?: {
pointsPerRinkWin?: number | undefined;
pointsPerRinkDraw?: number | undefined;
defaultRinks?: number | undefined;
enabled?: boolean | undefined;
} | undefined;
} | undefined;
teams?: Team[] | undefined;
matches?: any[] | undefined;
createdAt?: Date | undefined;
updatedAt?: Date | undefined;
});
_id: string;
name: string;
settings: {
pointsForWin: number;
pointsForDraw: number;
pointsForLoss: number;
promotionPositions: number | undefined;
relegationPositions: number | undefined;
timesTeamsPlayOther: number;
maxRinksPerSession: number | undefined;
};
teams: Team[];
matches: Match[];
createdAt: Date;
updatedAt: Date;
/**
* Add a team to the league
* @param {Team|Object} team - Team to add (either a Team instance or team data)
* @returns {boolean} - True if team was added, false if already exists
* @throws {Error} - If team data is invalid
*/
addTeam(team: Team | Object): boolean;
/**
* Remove a team from the league
* @param {string} teamId - ID of team to remove
* @returns {boolean} - True if team was removed, false if not found
*/
removeTeam(teamId: string): boolean;
/**
* Add a match to the league
* @param {Match|Object} match - Match instance or match data
* @returns {boolean} - True if match was added, false otherwise
* @throws {Error} - If match data is invalid
*/
addMatch(match: Match | Object): boolean;
/**
* Get a team by its ID
* @param {string} teamId - ID of the team
* @returns {Team|undefined} - The team if found, undefined otherwise
*/
getTeam(teamId: string): Team | undefined;
/**
* Get a match by its ID
* @param {string} matchId - The ID of the match
* @returns {Match|undefined} - The match if found, undefined otherwise
*/
getMatch(matchId: string): Match | undefined;
/**
* Get all matches for a team
* @param {string} teamId - ID of the team
* @returns {Array<Match>} - Array of matches involving the team
*/
getTeamMatches(teamId: string): Array<Match>;
/**
* Get statistics for a team
* @param {string} teamId - ID of the team
* @returns {Object} - Team statistics
*/
getTeamStats(teamId: string): Object;
getLeagueTable(): {
leagueData: {
shotDifference: number;
constructor: Function;
toString(): string;
toLocaleString(): string;
valueOf(): Object;
hasOwnProperty(v: PropertyKey): boolean;
isPrototypeOf(v: Object): boolean;
propertyIsEnumerable(v: PropertyKey): boolean;
teamId: string;
teamName: string;
}[];
metaData: {
name: string;
};
};
initialiseFixtures(startDate: any, schedulingParams?: {}): boolean;
/**
* Returns the filtered list of matches requiring attention, sorted by priority.
* @returns {Array}
*/
getMatchesRequiringAttention(): any[];
/**
* Returns a set of match IDs that are in scheduling conflict.
* @returns {Set<string>}
*/
getConflictingMatchIds(): Set<string>;
/**
* Convert league to JSON
* @returns {Object} - JSON representation of the league
*/
toJSON(): Object;
}
import { Team } from './Team.js';
import { Match } from './Match.js';