tods-competition-factory 2.2.35 → 2.2.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +2 -2
- package/dist/tods-competition-factory.development.cjs.js +59 -38
- package/dist/tods-competition-factory.development.cjs.js.map +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js.map +1 -1
- package/package.json +10 -10
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
function factoryVersion() {
|
|
6
|
-
return '2.2.
|
|
6
|
+
return '2.2.37';
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
const SINGLES_MATCHUP = 'SINGLES';
|
|
@@ -32159,10 +32159,11 @@ function validateSetScore(set, matchUpFormat, isDecidingSet, allowIncomplete) {
|
|
|
32159
32159
|
const { setTo, tiebreakAt, tiebreakFormat, tiebreakSet } = setFormat;
|
|
32160
32160
|
const tiebreakSetTo = tiebreakSet?.tiebreakTo;
|
|
32161
32161
|
const isTiebreakOnlyFormat = !!tiebreakSetTo && !setTo;
|
|
32162
|
-
const side1Score = set.side1Score || 0;
|
|
32163
|
-
const side2Score = set.side2Score || 0;
|
|
32164
32162
|
const side1TiebreakScore = set.side1TiebreakScore;
|
|
32165
32163
|
const side2TiebreakScore = set.side2TiebreakScore;
|
|
32164
|
+
const hasTiebreakScores = side1TiebreakScore !== undefined && side2TiebreakScore !== undefined;
|
|
32165
|
+
const side1Score = isTiebreakOnlyFormat && hasTiebreakScores ? side1TiebreakScore : set.side1Score || set.side1 || 0;
|
|
32166
|
+
const side2Score = isTiebreakOnlyFormat && hasTiebreakScores ? side2TiebreakScore : set.side2Score || set.side2 || 0;
|
|
32166
32167
|
const winnerScore = Math.max(side1Score, side2Score);
|
|
32167
32168
|
const loserScore = Math.min(side1Score, side2Score);
|
|
32168
32169
|
const scoreDiff = winnerScore - loserScore;
|
|
@@ -32179,36 +32180,43 @@ function validateSetScore(set, matchUpFormat, isDecidingSet, allowIncomplete) {
|
|
|
32179
32180
|
error: `Tiebreak-only set winner must reach at least ${tiebreakSetTo}, got ${winnerScore}`,
|
|
32180
32181
|
};
|
|
32181
32182
|
}
|
|
32182
|
-
if (
|
|
32183
|
+
if (scoreDiff < 2) {
|
|
32184
|
+
return {
|
|
32185
|
+
isValid: false,
|
|
32186
|
+
error: `Tiebreak-only set must be won by at least 2 points, got ${winnerScore}-${loserScore}`,
|
|
32187
|
+
};
|
|
32188
|
+
}
|
|
32189
|
+
if (winnerScore === tiebreakSetTo && loserScore > tiebreakSetTo - 2) {
|
|
32183
32190
|
return {
|
|
32184
32191
|
isValid: false,
|
|
32185
|
-
error: `Tiebreak-only set
|
|
32192
|
+
error: `Tiebreak-only set at ${tiebreakSetTo}-${loserScore} requires playing past ${tiebreakSetTo}`,
|
|
32186
32193
|
};
|
|
32187
32194
|
}
|
|
32188
|
-
if (scoreDiff !== 2) {
|
|
32195
|
+
if (winnerScore > tiebreakSetTo && scoreDiff !== 2) {
|
|
32189
32196
|
return {
|
|
32190
32197
|
isValid: false,
|
|
32191
|
-
error: `Tiebreak-only set must be won by exactly 2 points, got ${winnerScore}-${loserScore}`,
|
|
32198
|
+
error: `Tiebreak-only set past ${tiebreakSetTo} must be won by exactly 2 points, got ${winnerScore}-${loserScore}`,
|
|
32192
32199
|
};
|
|
32193
32200
|
}
|
|
32194
32201
|
return { isValid: true };
|
|
32195
32202
|
}
|
|
32196
32203
|
const hasExplicitTiebreak = side1TiebreakScore !== undefined || side2TiebreakScore !== undefined;
|
|
32197
32204
|
const isImplicitTiebreak = setTo && winnerScore === setTo + 1 && loserScore === setTo;
|
|
32198
|
-
const
|
|
32199
|
-
const hasTiebreak = hasExplicitTiebreak || isImplicitTiebreak || isLikelyTiebreak;
|
|
32205
|
+
const hasTiebreak = hasExplicitTiebreak || isImplicitTiebreak;
|
|
32200
32206
|
if (hasTiebreak) {
|
|
32201
|
-
if (setTo &&
|
|
32202
|
-
|
|
32207
|
+
if (setTo && tiebreakAt) {
|
|
32208
|
+
const expectedWinnerScore = tiebreakAt === setTo ? setTo + 1 : setTo;
|
|
32209
|
+
const expectedLoserScore = tiebreakAt;
|
|
32210
|
+
if (winnerScore !== expectedWinnerScore) {
|
|
32203
32211
|
return {
|
|
32204
32212
|
isValid: false,
|
|
32205
|
-
error: `Tiebreak set winner must have ${
|
|
32213
|
+
error: `Tiebreak set winner must have ${expectedWinnerScore} games, got ${winnerScore}`,
|
|
32206
32214
|
};
|
|
32207
32215
|
}
|
|
32208
|
-
if (loserScore !==
|
|
32216
|
+
if (loserScore !== expectedLoserScore) {
|
|
32209
32217
|
return {
|
|
32210
32218
|
isValid: false,
|
|
32211
|
-
error: `Tiebreak set loser must have ${
|
|
32219
|
+
error: `Tiebreak set loser must have ${expectedLoserScore} games, got ${loserScore}`,
|
|
32212
32220
|
};
|
|
32213
32221
|
}
|
|
32214
32222
|
}
|
|
@@ -32267,33 +32275,33 @@ function validateSetScore(set, matchUpFormat, isDecidingSet, allowIncomplete) {
|
|
|
32267
32275
|
error: `Set winner must reach ${setTo} games, got ${winnerScore}`,
|
|
32268
32276
|
};
|
|
32269
32277
|
}
|
|
32270
|
-
|
|
32278
|
+
const isTiebreakWon = tiebreakAt && winnerScore === setTo && loserScore === tiebreakAt && scoreDiff === 1;
|
|
32279
|
+
if (scoreDiff < 2 && !isTiebreakWon) {
|
|
32271
32280
|
return {
|
|
32272
32281
|
isValid: false,
|
|
32273
32282
|
error: `Set must be won by at least 2 games, got ${winnerScore}-${loserScore}`,
|
|
32274
32283
|
};
|
|
32275
32284
|
}
|
|
32276
32285
|
if (tiebreakAt) {
|
|
32277
|
-
if (loserScore >= tiebreakAt) {
|
|
32286
|
+
if (loserScore >= tiebreakAt && !isTiebreakWon) {
|
|
32278
32287
|
return {
|
|
32279
32288
|
isValid: false,
|
|
32280
32289
|
error: `When tied at ${tiebreakAt}-${tiebreakAt}, must play tiebreak. Use format like ${tiebreakAt + 1}-${tiebreakAt}(5)`,
|
|
32281
32290
|
};
|
|
32282
32291
|
}
|
|
32283
|
-
|
|
32292
|
+
const maxWinnerScore = tiebreakAt === setTo ? setTo + 1 : setTo;
|
|
32293
|
+
if (winnerScore > maxWinnerScore) {
|
|
32284
32294
|
return {
|
|
32285
32295
|
isValid: false,
|
|
32286
|
-
error: `With tiebreak format, set score cannot exceed ${
|
|
32296
|
+
error: `With tiebreak format, set score cannot exceed ${maxWinnerScore}-${tiebreakAt}. Got ${winnerScore}-${loserScore}`,
|
|
32287
32297
|
};
|
|
32288
32298
|
}
|
|
32289
32299
|
}
|
|
32290
|
-
else {
|
|
32291
|
-
|
|
32292
|
-
|
|
32293
|
-
|
|
32294
|
-
|
|
32295
|
-
};
|
|
32296
|
-
}
|
|
32300
|
+
else if (winnerScore > setTo + 10) {
|
|
32301
|
+
return {
|
|
32302
|
+
isValid: false,
|
|
32303
|
+
error: `Set score ${winnerScore}-${loserScore} exceeds reasonable limits`,
|
|
32304
|
+
};
|
|
32297
32305
|
}
|
|
32298
32306
|
}
|
|
32299
32307
|
return { isValid: true };
|
|
@@ -32304,12 +32312,14 @@ function validateMatchUpScore(sets, matchUpFormat, matchUpStatus) {
|
|
|
32304
32312
|
}
|
|
32305
32313
|
const bestOfMatch = matchUpFormat?.match(/SET(\d+)/)?.[1];
|
|
32306
32314
|
const bestOfSets = bestOfMatch ? Number.parseInt(bestOfMatch) : 3;
|
|
32307
|
-
const hasIncompleteSet = sets.some((set) => !set.winningSide);
|
|
32308
32315
|
const isIrregularEnding = [RETIRED$1, WALKOVER$2, DEFAULTED].includes(matchUpStatus || '');
|
|
32309
|
-
const allowIncomplete = isIrregularEnding || (!matchUpStatus && hasIncompleteSet);
|
|
32310
32316
|
for (let i = 0; i < sets.length; i++) {
|
|
32311
|
-
const
|
|
32312
|
-
const
|
|
32317
|
+
const set = sets[i];
|
|
32318
|
+
const isDecidingSet = i + 1 === bestOfSets;
|
|
32319
|
+
const setHasWinner = set.winningSide !== undefined;
|
|
32320
|
+
const matchInProgress = matchUpStatus === undefined;
|
|
32321
|
+
const allowIncomplete = isIrregularEnding || (matchInProgress && !setHasWinner);
|
|
32322
|
+
const setValidation = validateSetScore(set, matchUpFormat, isDecidingSet, allowIncomplete);
|
|
32313
32323
|
if (!setValidation.isValid) {
|
|
32314
32324
|
return {
|
|
32315
32325
|
isValid: false,
|
|
@@ -32498,15 +32508,15 @@ function getHighTiebreakValue(params) {
|
|
|
32498
32508
|
}
|
|
32499
32509
|
|
|
32500
32510
|
function parseScoreString({ tiebreakTo = 7, scoreString = '', matchUpFormat }) {
|
|
32501
|
-
let
|
|
32511
|
+
let parsedFormat;
|
|
32512
|
+
let bestOfSets = 3;
|
|
32502
32513
|
if (matchUpFormat) {
|
|
32503
32514
|
try {
|
|
32504
|
-
|
|
32505
|
-
const
|
|
32506
|
-
|
|
32507
|
-
isTiebreakOnlyFormat = !!tiebreakSetTo && !regularSetTo;
|
|
32515
|
+
parsedFormat = parse(matchUpFormat);
|
|
32516
|
+
const bestOfMatch = matchUpFormat?.match(/SET(\d+)/)?.[1];
|
|
32517
|
+
bestOfSets = bestOfMatch ? Number.parseInt(bestOfMatch) : 3;
|
|
32508
32518
|
}
|
|
32509
|
-
catch (
|
|
32519
|
+
catch (_e) {
|
|
32510
32520
|
}
|
|
32511
32521
|
}
|
|
32512
32522
|
return scoreString
|
|
@@ -32519,6 +32529,16 @@ function parseScoreString({ tiebreakTo = 7, scoreString = '', matchUpFormat }) {
|
|
|
32519
32529
|
const tiebreak = inParentheses.exec(set);
|
|
32520
32530
|
const bracketed = inBrackets.exec(set);
|
|
32521
32531
|
const isTiebreakOnlySet = set?.startsWith('[') && bracketed;
|
|
32532
|
+
let isTiebreakOnlyFormat = false;
|
|
32533
|
+
if (parsedFormat && isTiebreakOnlySet) {
|
|
32534
|
+
const isDecidingSet = setNumber === bestOfSets;
|
|
32535
|
+
const setFormat = isDecidingSet && parsedFormat.finalSetFormat ? parsedFormat.finalSetFormat : parsedFormat.setFormat;
|
|
32536
|
+
if (setFormat) {
|
|
32537
|
+
const tiebreakSetTo = setFormat.tiebreakSet?.tiebreakTo;
|
|
32538
|
+
const regularSetTo = setFormat.setTo;
|
|
32539
|
+
isTiebreakOnlyFormat = !!tiebreakSetTo && !regularSetTo;
|
|
32540
|
+
}
|
|
32541
|
+
}
|
|
32522
32542
|
let side1Score;
|
|
32523
32543
|
let side2Score;
|
|
32524
32544
|
let side1TiebreakScore;
|
|
@@ -32534,12 +32554,13 @@ function parseScoreString({ tiebreakTo = 7, scoreString = '', matchUpFormat }) {
|
|
|
32534
32554
|
else {
|
|
32535
32555
|
side1TiebreakScore = bracketedScores[0];
|
|
32536
32556
|
side2TiebreakScore = bracketedScores[1];
|
|
32537
|
-
winningSide =
|
|
32557
|
+
winningSide =
|
|
32558
|
+
(side1TiebreakScore > side2TiebreakScore && 1) || (side1TiebreakScore < side2TiebreakScore && 2) || undefined;
|
|
32538
32559
|
}
|
|
32539
32560
|
}
|
|
32540
32561
|
else {
|
|
32541
32562
|
const setString = (tiebreak && set.replace(tiebreak[0], '')) || (bracketed && set.replace(bracketed[0], '')) || set;
|
|
32542
|
-
const setScores = setString.split('-').map((score) => parseInt(score));
|
|
32563
|
+
const setScores = setString.split('-').map((score) => Number.parseInt(score));
|
|
32543
32564
|
side1Score = setScores[0];
|
|
32544
32565
|
side2Score = setScores[1];
|
|
32545
32566
|
winningSide = (side1Score > side2Score && 1) || (side1Score < side2Score && 2) || undefined;
|
|
@@ -32555,7 +32576,7 @@ function parseScoreString({ tiebreakTo = 7, scoreString = '', matchUpFormat }) {
|
|
|
32555
32576
|
}
|
|
32556
32577
|
}
|
|
32557
32578
|
if (bracketed && !isTiebreakOnlySet) {
|
|
32558
|
-
const matchTiebreakScores = bracketed[1].split('-').map((score) => parseInt(score));
|
|
32579
|
+
const matchTiebreakScores = bracketed[1].split('-').map((score) => Number.parseInt(score));
|
|
32559
32580
|
side1TiebreakScore = matchTiebreakScores[0];
|
|
32560
32581
|
side2TiebreakScore = matchTiebreakScores[1];
|
|
32561
32582
|
}
|