formula1.js
Version:
Formula 1 Ergast API Wrapper
118 lines (117 loc) • 3.74 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Driver = exports.Constructor = exports.DriverStanding = exports.ConstructorStanding = exports.Standing = exports.DriverStandings = exports.ConstructorStandings = exports.Standings = void 0;
const Request_1 = require("../Request");
class Standings {
constructor(year, round, limit) {
this.year = year;
this.round = round;
this.limit = limit;
}
pop;
year;
round;
limit;
initialized = false;
season;
completedRounds;
standings;
}
exports.Standings = Standings;
class ConstructorStandings extends Standings {
pop = async () => {
const defaultLimit = 30;
const round = `${this.round != null && this.round > 0
? `/${Math.floor(this.round)}`
: ''}`;
const data = (await (0, Request_1.Request)(`${this.year}${round}/constructorStandings`, `limit=${this.limit || defaultLimit}`));
const standings = data.MRData.StandingsTable.StandingsLists[0];
this.season = parseInt(standings.season);
this.completedRounds = parseInt(standings.round);
this.standings = standings.ConstructorStandings.map(s => new ConstructorStanding(this, s));
this.initialized = true;
return this;
};
}
exports.ConstructorStandings = ConstructorStandings;
class DriverStandings extends Standings {
pop = async () => {
const defaultLimit = 150;
const round = `${this.round != null && this.round > 0
? `/${Math.floor(this.round)}`
: ''}`;
const data = (await (0, Request_1.Request)(`${this.year}${round}/driverStandings`, `limit=${this.limit || defaultLimit}`));
const standings = data.MRData.StandingsTable.StandingsLists[0];
this.season = parseInt(standings.season);
this.completedRounds = parseInt(standings.round);
this.standings = standings.DriverStandings.map(s => new DriverStanding(this, s));
this.initialized = true;
return this;
};
}
exports.DriverStandings = DriverStandings;
class Standing {
constructor(s, data) {
this.position = parseInt(data.position);
this.points = parseFloat(data.points);
this.wins = parseInt(data.wins);
this.standings = s;
}
standings;
position;
points;
wins;
team;
}
exports.Standing = Standing;
class ConstructorStanding extends Standing {
constructor(s, data) {
super(s, data);
this.team = new Constructor(this, data.Constructor);
}
}
exports.ConstructorStanding = ConstructorStanding;
class DriverStanding extends Standing {
constructor(s, data) {
super(s, data);
this.team = new Constructor(this, data.Constructors[0]);
this.driver = new Driver(this, data.Driver);
}
driver;
}
exports.DriverStanding = DriverStanding;
class Constructor {
constructor(s, data) {
this.id = data.constructorId;
this.name = data.name;
this.nationality = data.nationality;
this.standing = s;
}
standing;
id;
name;
nationality;
}
exports.Constructor = Constructor;
class Driver {
constructor(s, data) {
this.id = data.driverId;
this.permanentNumber = data.permanentNumber;
this.code = data.code;
this.firstName = data.givenName;
this.lastName = data.familyName;
this.dateOfBirth = data.dateOfBirth;
this.nationality = data.nationality;
this.standing = s;
}
standing;
id;
permanentNumber;
code;
firstName;
lastName;
dateOfBirth;
nationality;
fullName = () => `${this.firstName} ${this.lastName}`;
}
exports.Driver = Driver;