soccer-go
Version:
Soccer CLI for stats and results.
59 lines (58 loc) • 1.53 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const picocolors_1 = __importDefault(require("picocolors"));
class Standing {
rank;
team;
playedGames;
points;
goals;
goalsAgainst;
goalDifference;
wins;
draws;
losses;
form;
constructor(data) {
this.rank = data.position;
this.team = data.team.name;
this.playedGames = data.playedGames;
this.points = data.points;
this.goals = data.goalsFor;
this.goalsAgainst = data.goalsAgainst;
this.goalDifference = data.goalDifference;
this.wins = data.won;
this.draws = data.draw;
this.losses = data.lost;
this.form = data.form;
}
toRow = () => [
this.rank,
this.team,
this.playedGames,
this.points,
this.wins,
this.draws,
this.losses,
this.goals,
this.goalsAgainst,
this.goalDifference,
formatForm(this.form),
];
}
exports.default = Standing;
const formatters = {
W: picocolors_1.default.bgGreen,
D: picocolors_1.default.bgYellow,
L: picocolors_1.default.bgRed,
};
function formatForm(form) {
if (!form) {
return '';
}
const results = form.split(',');
return results.map((r) => formatters[r](' ' + picocolors_1.default.bold(r) + ' ')).join(' ');
}