@mxfb/tools 0.0.43 → 0.2.3

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.
Files changed (133) hide show
  1. package/agnostic/_WIP_tennis/index.js +62 -0
  2. package/agnostic/index.d.ts +4 -0
  3. package/agnostic/misc/elo/index.d.ts +31 -0
  4. package/agnostic/misc/elo/index.js +6 -0
  5. package/agnostic/misc/index.d.ts +6 -0
  6. package/agnostic/misc/index.js +16 -0
  7. package/agnostic/misc/tennis/index.d.ts +60 -0
  8. package/agnostic/misc/tennis/index.js +6 -0
  9. package/chunks/chunk-TTZHPIH7.js +237 -0
  10. package/chunks/chunk-ZC5RZBNY.js +33 -0
  11. package/components/index.d.ts +1 -0
  12. package/node/index.d.ts +2 -0
  13. package/node/mxfb-cli-config/index.js +113 -0
  14. package/package.json +18 -19
  15. package/shared/errors/index.d.ts +138 -0
  16. package/shared/index.d.ts +0 -0
  17. package/chunks/chunk-BEZTX3QU.js +0 -1
  18. package/chunks/chunk-BW5CY5YB.js +0 -1
  19. package/chunks/chunk-DIPJ73JH.js +0 -1
  20. package/chunks/chunk-EFFU6KXJ.js +0 -1
  21. package/chunks/chunk-KNE7WIIW.js +0 -1
  22. package/chunks/chunk-LCLAV6Q2.js +0 -1
  23. package/chunks/chunk-PCAKH6ZJ.js +0 -1
  24. package/chunks/chunk-QQRJPDR7.js +0 -1
  25. package/chunks/chunk-WZBNXYN3.js +0 -1
  26. package/chunks/chunk-XCKXCF4A.js +0 -1
  27. package/chunks/chunk-ZVJO36JU.js +0 -1
  28. package/components/Comp/index.d.ts +0 -1
  29. package/components/Comp/index.js +0 -1
  30. package/index.js +0 -102
  31. package/utils/agnostic/_WIP_tennis/index.js +0 -1
  32. package/utils/agnostic/absolute-modulo/index.d.ts +0 -1
  33. package/utils/agnostic/absolute-modulo/index.js +0 -1
  34. package/utils/agnostic/array/index.d.ts +0 -7
  35. package/utils/agnostic/array/index.js +0 -1
  36. package/utils/agnostic/assert/index.d.ts +0 -3
  37. package/utils/agnostic/assert/index.js +0 -1
  38. package/utils/agnostic/await-timeout/index.d.ts +0 -2
  39. package/utils/agnostic/await-timeout/index.js +0 -1
  40. package/utils/agnostic/bem/BEM.d.ts +0 -29
  41. package/utils/agnostic/bem/getNamesArr.d.ts +0 -2
  42. package/utils/agnostic/bem/index.d.ts +0 -5
  43. package/utils/agnostic/bem/index.js +0 -1
  44. package/utils/agnostic/cast/index.d.ts +0 -7
  45. package/utils/agnostic/cast/index.js +0 -1
  46. package/utils/agnostic/charcode-string/index.d.ts +0 -2
  47. package/utils/agnostic/charcode-string/index.js +0 -1
  48. package/utils/agnostic/clamp/index.d.ts +0 -1
  49. package/utils/agnostic/clamp/index.js +0 -1
  50. package/utils/agnostic/clientside-html-sanitizer/index.d.ts +0 -22
  51. package/utils/agnostic/clientside-html-sanitizer/index.js +0 -1
  52. package/utils/agnostic/crossenv/index.d.ts +0 -11
  53. package/utils/agnostic/crossenv/index.js +0 -1
  54. package/utils/agnostic/flatten-getters/index.d.ts +0 -1
  55. package/utils/agnostic/flatten-getters/index.js +0 -1
  56. package/utils/agnostic/generate-html-placeholders/index.d.ts +0 -7
  57. package/utils/agnostic/generate-html-placeholders/index.js +0 -5
  58. package/utils/agnostic/generate-nice-color/index.d.ts +0 -3
  59. package/utils/agnostic/generate-nice-color/index.js +0 -1
  60. package/utils/agnostic/insert-node/index.d.ts +0 -2
  61. package/utils/agnostic/insert-node/index.js +0 -1
  62. package/utils/agnostic/interpolate/index.d.ts +0 -3
  63. package/utils/agnostic/interpolate/index.js +0 -1
  64. package/utils/agnostic/is-array-of/index.d.ts +0 -5
  65. package/utils/agnostic/is-array-of/index.js +0 -1
  66. package/utils/agnostic/is-constructor-function/index.d.ts +0 -2
  67. package/utils/agnostic/is-constructor-function/index.js +0 -1
  68. package/utils/agnostic/is-falsy/index.d.ts +0 -8
  69. package/utils/agnostic/is-falsy/index.js +0 -1
  70. package/utils/agnostic/is-in-enum/index.d.ts +0 -1
  71. package/utils/agnostic/is-in-enum/index.js +0 -1
  72. package/utils/agnostic/is-nullish/index.d.ts +0 -5
  73. package/utils/agnostic/is-nullish/index.js +0 -1
  74. package/utils/agnostic/is-object/index.d.ts +0 -1
  75. package/utils/agnostic/is-object/index.js +0 -1
  76. package/utils/agnostic/is-record/index.d.ts +0 -1
  77. package/utils/agnostic/is-record/index.js +0 -1
  78. package/utils/agnostic/is-valid-css-class-name/index.d.ts +0 -2
  79. package/utils/agnostic/is-valid-css-class-name/index.js +0 -1
  80. package/utils/agnostic/memoize/index.d.ts +0 -3
  81. package/utils/agnostic/memoize/index.js +0 -1
  82. package/utils/agnostic/object-validate-from-partial/index.d.ts +0 -1
  83. package/utils/agnostic/object-validate-from-partial/index.js +0 -1
  84. package/utils/agnostic/random/index.d.ts +0 -9
  85. package/utils/agnostic/random/index.js +0 -1
  86. package/utils/agnostic/record-format/index.d.ts +0 -11
  87. package/utils/agnostic/record-format/index.js +0 -1
  88. package/utils/agnostic/regexp/index.d.ts +0 -21
  89. package/utils/agnostic/regexp/index.js +0 -1
  90. package/utils/agnostic/replace-all/index.d.ts +0 -1
  91. package/utils/agnostic/replace-all/index.js +0 -1
  92. package/utils/agnostic/responsive-harmonics/index.d.ts +0 -10
  93. package/utils/agnostic/responsive-harmonics/index.js +0 -1
  94. package/utils/agnostic/round-numbers/index.d.ts +0 -1
  95. package/utils/agnostic/round-numbers/index.js +0 -1
  96. package/utils/agnostic/selector-to-element/index.d.ts +0 -1
  97. package/utils/agnostic/selector-to-element/index.js +0 -1
  98. package/utils/agnostic/silent-log/index.d.ts +0 -53
  99. package/utils/agnostic/silent-log/index.js +0 -9
  100. package/utils/agnostic/str-to-nodes/index.d.ts +0 -7
  101. package/utils/agnostic/str-to-nodes/index.js +0 -1
  102. package/utils/agnostic/string-matches/index.d.ts +0 -4
  103. package/utils/agnostic/string-matches/index.js +0 -1
  104. package/utils/agnostic/string-normalize-indent/index.d.ts +0 -1
  105. package/utils/agnostic/string-normalize-indent/index.js +0 -3
  106. package/utils/agnostic/throttle-debounce/index.d.ts +0 -30
  107. package/utils/agnostic/throttle-debounce/index.js +0 -1
  108. package/utils/agnostic/throttle-debounce/types.d.ts +0 -3
  109. package/utils/agnostic/to-alphanum/index.d.ts +0 -1
  110. package/utils/agnostic/to-alphanum/index.js +0 -1
  111. package/utils/agnostic/transition/index.d.ts +0 -39
  112. package/utils/agnostic/transition/index.js +0 -1
  113. package/utils/agnostic/wait/index.d.ts +0 -1
  114. package/utils/agnostic/wait/index.js +0 -1
  115. package/utils/browser/dynamic-css/index.d.ts +0 -4
  116. package/utils/browser/dynamic-css/index.js +0 -2
  117. package/utils/browser/get-current-downlink/index.d.ts +0 -1
  118. package/utils/browser/get-current-downlink/index.js +0 -1
  119. package/utils/browser/get-node-ancestors/index.d.ts +0 -1
  120. package/utils/browser/get-node-ancestors/index.js +0 -1
  121. package/utils/node/image/index.d.ts +0 -9
  122. package/utils/node/image/index.js +0 -1
  123. package/utils/node/is-in-directory/index.d.ts +0 -1
  124. package/utils/node/is-in-directory/index.js +0 -1
  125. package/utils/node/list-subpaths/index.d.ts +0 -33
  126. package/utils/node/list-subpaths/index.js +0 -1
  127. package/utils/node/mxfb-cli-config/index.js +0 -2
  128. package/utils/node/process-exit/index.d.ts +0 -5
  129. package/utils/node/process-exit/index.js +0 -1
  130. package/utils/node/read-write-file/index.d.ts +0 -12
  131. package/utils/node/read-write-file/index.js +0 -1
  132. /package/{utils/agnostic → agnostic}/_WIP_tennis/index.d.ts +0 -0
  133. /package/{utils/node → node}/mxfb-cli-config/index.d.ts +0 -0
@@ -0,0 +1,62 @@
1
+ // src/agnostic/_WIP_tennis/index.ts
2
+ var Tennis;
3
+ ((Tennis2) => {
4
+ function getGameScore(game) {
5
+ const score = [0, 0];
6
+ game.forEach((point) => {
7
+ if (score.includes(5)) return;
8
+ const winnerPos = point ? 0 : 1;
9
+ const loserPos = point ? 1 : 0;
10
+ const winnerCurrScore = score[winnerPos];
11
+ const loserCurrScore = score[loserPos];
12
+ if (loserCurrScore === 5 || winnerCurrScore === 5) return;
13
+ if (loserCurrScore === 4 && winnerCurrScore === 3) {
14
+ score[loserPos] = 3;
15
+ return;
16
+ }
17
+ if (loserCurrScore === 3 && winnerCurrScore === 4) {
18
+ score[winnerPos] = 5;
19
+ return;
20
+ }
21
+ if (winnerCurrScore === 3) {
22
+ score[winnerPos] = 5;
23
+ return;
24
+ }
25
+ score[winnerPos]++;
26
+ return;
27
+ });
28
+ return score;
29
+ }
30
+ function getGameWinner(gameScore) {
31
+ const [scoreA, scoreB] = gameScore;
32
+ if (scoreA === 5) return true;
33
+ if (scoreB === 5) return false;
34
+ return null;
35
+ }
36
+ function getSetScore(set) {
37
+ const score = [0, 0];
38
+ let foundUnfinishedGame = false;
39
+ set.forEach((game) => {
40
+ if (foundUnfinishedGame) return;
41
+ if (score.includes(7)) return;
42
+ const [scoreA, scoreB] = score;
43
+ if (scoreA >= 6 && scoreB < 5) return;
44
+ if (scoreB <= 6 && scoreA < 5) return;
45
+ const gameScore = getGameScore(game);
46
+ const gameWinner = getGameWinner(gameScore);
47
+ if (gameWinner === true) {
48
+ score[0]++;
49
+ return;
50
+ }
51
+ if (gameWinner === false) {
52
+ score[1]++;
53
+ return;
54
+ }
55
+ foundUnfinishedGame = true;
56
+ });
57
+ return score;
58
+ }
59
+ })(Tennis || (Tennis = {}));
60
+ export {
61
+ Tennis
62
+ };
@@ -0,0 +1,4 @@
1
+ import * as MiscNamespace from './misc';
2
+ export declare namespace Agnostic {
3
+ export import Misc = MiscNamespace;
4
+ }
@@ -0,0 +1,31 @@
1
+ export declare namespace Elo {
2
+ const K_FACTOR = 32;
3
+ /**
4
+ * Calcule la probabilité de gain de A en fonction des scores Elo de A et B.
5
+ * @param eloA Le score Elo du joueur A.
6
+ * @param eloB Le score Elo du joueur B.
7
+ * @returns La probabilité que le joueur A gagne contre le joueur B.
8
+ */
9
+ function getWinProbability(eloA: number, eloB: number): number;
10
+ /**
11
+ * Calcule les nouveaux classements Elo pour les scénarios de victoire de A, de B et de match nul.
12
+ * @param eloA Le score Elo actuel du joueur A.
13
+ * @param eloB Le score Elo actuel du joueur B.
14
+ * @param kFactor Facteur K pour les calculs Elo (facultatif, valeur par défaut = 32).
15
+ * @returns Un objet contenant les nouveaux classements Elo pour chaque scénario de résultat.
16
+ */
17
+ function getOutcome(eloA: number, eloB: number, kFactor?: number): {
18
+ aWins: {
19
+ eloA: number;
20
+ eloB: number;
21
+ };
22
+ bWins: {
23
+ eloA: number;
24
+ eloB: number;
25
+ };
26
+ null: {
27
+ eloA: number;
28
+ eloB: number;
29
+ };
30
+ };
31
+ }
@@ -0,0 +1,6 @@
1
+ import {
2
+ Elo
3
+ } from "../../../chunks/chunk-ZC5RZBNY.js";
4
+ export {
5
+ Elo
6
+ };
@@ -0,0 +1,6 @@
1
+ import { Elo as EloNamespace } from './elo';
2
+ import { Tennis as TennisNamespace } from './tennis';
3
+ export declare namespace Misc {
4
+ export import Elo = EloNamespace;
5
+ export import Tennis = TennisNamespace;
6
+ }
@@ -0,0 +1,16 @@
1
+ import {
2
+ Elo
3
+ } from "../../chunks/chunk-ZC5RZBNY.js";
4
+ import {
5
+ Tennis
6
+ } from "../../chunks/chunk-TTZHPIH7.js";
7
+
8
+ // src/agnostic/misc/index.ts
9
+ var Misc;
10
+ ((Misc2) => {
11
+ Misc2.Elo = Elo;
12
+ Misc2.Tennis = Tennis;
13
+ })(Misc || (Misc = {}));
14
+ export {
15
+ Misc
16
+ };
@@ -0,0 +1,60 @@
1
+ export declare namespace Tennis {
2
+ namespace Score {
3
+ type PointDescriptor = boolean;
4
+ type GameFormat = {
5
+ upTo: number;
6
+ diffToWin: number;
7
+ };
8
+ class Game {
9
+ private format;
10
+ private pointsSequence;
11
+ constructor(format: GameFormat);
12
+ add(point: PointDescriptor): this;
13
+ getNumericScore(): [number, number];
14
+ static numericToStringScoreValue(numScore: [number, number]): string;
15
+ getScore(): string;
16
+ isFinished(): boolean;
17
+ getWinner(): boolean | null;
18
+ }
19
+ type SetFormat = {
20
+ upTo: number;
21
+ diffToWin: number;
22
+ gamesFormat: GameFormat;
23
+ tieBreakAt: number | null;
24
+ tieBreakFormat: GameFormat;
25
+ };
26
+ class Set {
27
+ private format;
28
+ private pointsSequence;
29
+ constructor(format: SetFormat);
30
+ add(point: PointDescriptor): void;
31
+ getGames(): Game[];
32
+ getNumericScore(): {
33
+ games: [number, number];
34
+ currentGame?: [number, number];
35
+ };
36
+ getScore(): string;
37
+ isFinished(): boolean;
38
+ getWinner(): boolean | null;
39
+ }
40
+ type MatchFormat = {
41
+ upTo: number;
42
+ setsFormat: SetFormat;
43
+ lastSetFormat: SetFormat;
44
+ };
45
+ class Match {
46
+ private format;
47
+ private pointsSequence;
48
+ constructor(format: MatchFormat);
49
+ add(point: PointDescriptor): void;
50
+ getSets(): Set[];
51
+ getNumericScore(): {
52
+ sets: [number, number][];
53
+ currentGame?: [number, number];
54
+ };
55
+ getScore(): string;
56
+ isFinished(): boolean;
57
+ getWinner(): boolean | null;
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,6 @@
1
+ import {
2
+ Tennis
3
+ } from "../../../chunks/chunk-TTZHPIH7.js";
4
+ export {
5
+ Tennis
6
+ };
@@ -0,0 +1,237 @@
1
+ // src/agnostic/misc/tennis/index.ts
2
+ var Tennis;
3
+ ((Tennis2) => {
4
+ let Score;
5
+ ((Score2) => {
6
+ class Game {
7
+ format;
8
+ pointsSequence = [];
9
+ constructor(format) {
10
+ this.format = format;
11
+ }
12
+ add(point) {
13
+ if (!this.isFinished()) this.pointsSequence.push(point);
14
+ return this;
15
+ }
16
+ getNumericScore() {
17
+ const { pointsSequence, format } = this;
18
+ const { upTo, diffToWin } = format;
19
+ return pointsSequence.reduce((reduced, point) => {
20
+ const [aScore, bScore] = reduced;
21
+ const aWon = aScore >= upTo && aScore - bScore >= diffToWin;
22
+ const bWon = bScore >= upTo && bScore - aScore >= diffToWin;
23
+ if (aWon || bWon) return reduced;
24
+ return point ? [aScore + 1, bScore] : [aScore, bScore + 1];
25
+ }, [0, 0]);
26
+ }
27
+ static numericToStringScoreValue(numScore) {
28
+ const [aScore, bScore] = numScore;
29
+ if (aScore >= 3 && bScore >= 3) {
30
+ if (aScore === bScore) return "deuce";
31
+ if (aScore < bScore) return "Ad/40";
32
+ return "40/Ad";
33
+ }
34
+ const strScoresList = ["0", "15", "30", "40"];
35
+ return `${strScoresList.at(aScore) ?? "?"}/${strScoresList.at(bScore) ?? "?"}`;
36
+ }
37
+ getScore() {
38
+ return Game.numericToStringScoreValue(this.getNumericScore());
39
+ }
40
+ isFinished() {
41
+ const { format } = this;
42
+ const { upTo, diffToWin } = format;
43
+ const [aScore, bScore] = this.getNumericScore();
44
+ const maxScoreReached = Math.max(aScore, bScore) >= upTo;
45
+ const diffReached = Math.abs(aScore - bScore) >= diffToWin;
46
+ if (maxScoreReached && diffReached) return true;
47
+ return false;
48
+ }
49
+ getWinner() {
50
+ if (!this.isFinished()) return null;
51
+ const [aScore, bScore] = this.getNumericScore();
52
+ return aScore > bScore;
53
+ }
54
+ }
55
+ Score2.Game = Game;
56
+ class Set {
57
+ format;
58
+ pointsSequence = [];
59
+ constructor(format) {
60
+ this.format = format;
61
+ }
62
+ add(point) {
63
+ this.pointsSequence.push(point);
64
+ }
65
+ getGames() {
66
+ const { format } = this;
67
+ const { upTo, diffToWin, gamesFormat, tieBreakFormat, tieBreakAt } = format;
68
+ let aGames = 0;
69
+ let bGames = 0;
70
+ const games = [];
71
+ const { pointsSequence } = this;
72
+ pointsSequence.forEach((point) => {
73
+ const maxGamesReached = Math.max(aGames, bGames) >= upTo;
74
+ const diffReached = Math.abs(aGames - bGames) >= diffToWin;
75
+ if (maxGamesReached && diffReached) return;
76
+ const lastGameInList = games.at(-1);
77
+ const lastGameIsFinished = lastGameInList?.isFinished();
78
+ if (lastGameInList === void 0 || lastGameIsFinished === true) {
79
+ const isTiebreak = aGames === bGames && aGames === tieBreakAt;
80
+ if (isTiebreak) games.push(new Game(tieBreakFormat));
81
+ else games.push(new Game(gamesFormat));
82
+ }
83
+ const currentGame = games.at(-1);
84
+ if (currentGame === void 0) throw "Something went wrong, this should't be undefined";
85
+ currentGame.add(point);
86
+ const currentGameWinner = currentGame.getWinner();
87
+ if (currentGameWinner === true) {
88
+ aGames += 1;
89
+ }
90
+ if (currentGameWinner === false) {
91
+ bGames += 1;
92
+ }
93
+ });
94
+ return games;
95
+ }
96
+ getNumericScore() {
97
+ const games = this.getGames();
98
+ let aScore = 0;
99
+ let bScore = 0;
100
+ games.forEach((game) => {
101
+ const winner = game.getWinner();
102
+ if (winner === true) {
103
+ aScore++;
104
+ }
105
+ if (winner === false) {
106
+ bScore++;
107
+ }
108
+ });
109
+ const lastGame = games.at(-1);
110
+ if (lastGame === void 0) return { games: [aScore, bScore] };
111
+ if (lastGame.isFinished() === false) return {
112
+ games: [aScore, bScore],
113
+ currentGame: lastGame.getNumericScore()
114
+ };
115
+ return { games: [aScore, bScore] };
116
+ }
117
+ getScore() {
118
+ const numericScore = this.getNumericScore();
119
+ const { games, currentGame } = numericScore;
120
+ if (currentGame === void 0) return `${games.join("/")}`;
121
+ return `${games.join("/")} ${Game.numericToStringScoreValue(currentGame)}`;
122
+ }
123
+ isFinished() {
124
+ const { format } = this;
125
+ const { upTo, diffToWin, tieBreakAt } = format;
126
+ const [aScore, bScore] = this.getNumericScore().games;
127
+ const maxGamesReached = Math.max(aScore, bScore) >= upTo;
128
+ const diffReached = Math.abs(aScore - bScore) >= diffToWin;
129
+ const tieBreakBeenPlayed = tieBreakAt !== null && Math.max(aScore, bScore) > tieBreakAt;
130
+ return tieBreakBeenPlayed || maxGamesReached && diffReached;
131
+ }
132
+ getWinner() {
133
+ if (!this.isFinished()) return null;
134
+ const [aScore, bScore] = this.getNumericScore().games;
135
+ return aScore > bScore;
136
+ }
137
+ }
138
+ Score2.Set = Set;
139
+ class Match {
140
+ format;
141
+ pointsSequence = [];
142
+ constructor(format) {
143
+ this.format = format;
144
+ }
145
+ add(point) {
146
+ this.pointsSequence.push(point);
147
+ }
148
+ getSets() {
149
+ const { format } = this;
150
+ const { upTo, setsFormat, lastSetFormat } = format;
151
+ let aSets = 0;
152
+ let bSets = 0;
153
+ const sets = [];
154
+ const { pointsSequence } = this;
155
+ pointsSequence.forEach((point) => {
156
+ const maxSetsReached = Math.max(aSets, bSets) >= upTo;
157
+ if (maxSetsReached) return;
158
+ const lastSetInList = sets.at(-1);
159
+ const lastSetIsFinished = lastSetInList?.isFinished();
160
+ if (lastSetInList === void 0 || lastSetIsFinished === true) {
161
+ const isLastSet = aSets === bSets && aSets === upTo - 1;
162
+ if (isLastSet) sets.push(new Set(lastSetFormat));
163
+ else sets.push(new Set(setsFormat));
164
+ }
165
+ const currentSet = sets.at(-1);
166
+ if (currentSet === void 0) throw "Something went wrong, this should't be undefined";
167
+ currentSet.add(point);
168
+ const currentSetWinner = currentSet.getWinner();
169
+ if (currentSetWinner === true) {
170
+ aSets += 1;
171
+ }
172
+ if (currentSetWinner === false) {
173
+ bSets += 1;
174
+ }
175
+ });
176
+ return sets;
177
+ }
178
+ getNumericScore() {
179
+ const sets = this.getSets();
180
+ const numericScore = {
181
+ sets: [],
182
+ currentGame: void 0
183
+ };
184
+ sets.forEach((set) => {
185
+ const setNumericScore = set.getNumericScore();
186
+ const { games, currentGame } = setNumericScore;
187
+ numericScore.sets.push(games);
188
+ if (currentGame !== void 0) {
189
+ numericScore.currentGame = currentGame;
190
+ }
191
+ });
192
+ return numericScore;
193
+ }
194
+ getScore() {
195
+ return this.getSets().map((set) => set.getScore()).join(" ");
196
+ }
197
+ isFinished() {
198
+ const { format } = this;
199
+ const { upTo } = format;
200
+ const sets = this.getSets();
201
+ let aSets = 0;
202
+ let bSets = 0;
203
+ sets.forEach((set) => {
204
+ const winner = set.getWinner();
205
+ if (winner === true) {
206
+ aSets++;
207
+ }
208
+ if (winner === false) {
209
+ bSets++;
210
+ }
211
+ });
212
+ return Math.max(aSets, bSets) >= upTo;
213
+ }
214
+ getWinner() {
215
+ if (!this.isFinished()) return null;
216
+ const sets = this.getSets();
217
+ let aSets = 0;
218
+ let bSets = 0;
219
+ sets.forEach((set) => {
220
+ const winner = set.getWinner();
221
+ if (winner === true) {
222
+ aSets++;
223
+ }
224
+ if (winner === false) {
225
+ bSets++;
226
+ }
227
+ });
228
+ return aSets > bSets;
229
+ }
230
+ }
231
+ Score2.Match = Match;
232
+ })(Score = Tennis2.Score || (Tennis2.Score = {}));
233
+ })(Tennis || (Tennis = {}));
234
+
235
+ export {
236
+ Tennis
237
+ };
@@ -0,0 +1,33 @@
1
+ // src/agnostic/misc/elo/index.ts
2
+ var Elo;
3
+ ((Elo2) => {
4
+ Elo2.K_FACTOR = 32;
5
+ function getWinProbability(eloA, eloB) {
6
+ const exponent = (eloB - eloA) / 400;
7
+ return 1 / (1 + Math.pow(10, exponent));
8
+ }
9
+ Elo2.getWinProbability = getWinProbability;
10
+ function getOutcome(eloA, eloB, kFactor = Elo2.K_FACTOR) {
11
+ const probA = getWinProbability(eloA, eloB);
12
+ const probB = 1 - probA;
13
+ return {
14
+ aWins: {
15
+ eloA: Math.round(eloA + kFactor * (1 - probA)),
16
+ eloB: Math.round(eloB + kFactor * (0 - probB))
17
+ },
18
+ bWins: {
19
+ eloA: Math.round(eloA + kFactor * (0 - probA)),
20
+ eloB: Math.round(eloB + kFactor * (1 - probB))
21
+ },
22
+ null: {
23
+ eloA: Math.round(eloA + kFactor * (0.5 - probA)),
24
+ eloB: Math.round(eloB + kFactor * (0.5 - probB))
25
+ }
26
+ };
27
+ }
28
+ Elo2.getOutcome = getOutcome;
29
+ })(Elo || (Elo = {}));
30
+
31
+ export {
32
+ Elo
33
+ };
@@ -0,0 +1 @@
1
+ export declare namespace Components { }
@@ -0,0 +1,2 @@
1
+ import * as MxfbCliConfig from './mxfb-cli-config';
2
+ export { MxfbCliConfig };
@@ -0,0 +1,113 @@
1
+ // src/node/mxfb-cli-config/index.ts
2
+ import os from "node:os";
3
+ import { promises as fs } from "node:fs";
4
+ import path from "node:path";
5
+ var homeDirPath = os.homedir();
6
+ var mxfbConfigDirPath = path.join(homeDirPath, ".config/mxfb-cli");
7
+ var mxfbConfigFilePath = path.join(mxfbConfigDirPath, "config.json");
8
+ var emptyConfigObj = {};
9
+ async function createConfigFile(force = false) {
10
+ await fs.mkdir(mxfbConfigDirPath, { recursive: true });
11
+ try {
12
+ await fs.stat(mxfbConfigFilePath);
13
+ if (force === true) throw "create anyway";
14
+ return true;
15
+ } catch (err) {
16
+ try {
17
+ await fs.writeFile(
18
+ mxfbConfigFilePath,
19
+ `${JSON.stringify(emptyConfigObj, null, 2)}
20
+ `,
21
+ { encoding: "utf-8" }
22
+ );
23
+ return true;
24
+ } catch (err2) {
25
+ if (err2 instanceof Error) return err2;
26
+ if (typeof err2 === "string") return new Error(err2);
27
+ return new Error(`${err2}`);
28
+ }
29
+ }
30
+ }
31
+ var deletionSecurityPhrase = "THIS IS A DESTRUCTIVE AND DEFINITIVE ACTION";
32
+ async function deleteConfigDir(security) {
33
+ if (security !== deletionSecurityPhrase) return new Error("You must provide the security phrase");
34
+ await fs.rm(mxfbConfigDirPath, { recursive: true, force: true });
35
+ return true;
36
+ }
37
+ async function deleteConfigFile(security) {
38
+ if (security !== deletionSecurityPhrase) return new Error("You must provide the security phrase");
39
+ await fs.rm(mxfbConfigDirPath);
40
+ return true;
41
+ }
42
+ async function ensureConfigFile() {
43
+ try {
44
+ await fs.stat(mxfbConfigFilePath);
45
+ return true;
46
+ } catch (err) {
47
+ try {
48
+ const created = await createConfigFile();
49
+ if (created instanceof Error) throw created;
50
+ return true;
51
+ } catch (err2) {
52
+ if (err2 instanceof Error) return err2;
53
+ if (typeof err2 === "string") return new Error(err2);
54
+ return new Error(`${err2}`);
55
+ }
56
+ }
57
+ }
58
+ async function getConfigFile() {
59
+ try {
60
+ const fileContents = await fs.readFile(mxfbConfigFilePath, { encoding: "utf-8" });
61
+ return fileContents;
62
+ } catch (err) {
63
+ if (err instanceof Error) return err;
64
+ if (typeof err === "string") return new Error(err);
65
+ return new Error(`${err}`);
66
+ }
67
+ }
68
+ function validateConfigObj(configObj) {
69
+ return true;
70
+ }
71
+ function parseConfigFile(fileContents) {
72
+ try {
73
+ const parsed = JSON.parse(fileContents);
74
+ const validated = validateConfigObj(parsed);
75
+ if (!validated) throw new Error(`Invalid config file shape: ${fileContents}`);
76
+ return parsed;
77
+ } catch (err) {
78
+ if (err instanceof Error) return err;
79
+ if (typeof err === "string") return new Error(err);
80
+ return new Error(`${err}`);
81
+ }
82
+ }
83
+ async function getConfig(create = false) {
84
+ if (create) {
85
+ const created = await ensureConfigFile();
86
+ if (created !== true) return created;
87
+ }
88
+ const configStr = await getConfigFile();
89
+ if (configStr instanceof Error) return configStr;
90
+ const parsed = parseConfigFile(configStr);
91
+ if (parsed instanceof Error) return parsed;
92
+ return parsed;
93
+ }
94
+ async function updateConfig(updater, create = false) {
95
+ const currentConfig = await getConfig(create);
96
+ if (currentConfig instanceof Error) return currentConfig;
97
+ const updatedConfig = typeof updater === "function" ? updater(currentConfig) : { ...currentConfig, ...updater };
98
+ const stringified = JSON.stringify(updatedConfig, null, 2);
99
+ await fs.writeFile(mxfbConfigFilePath, stringified, { encoding: "utf-8" });
100
+ return true;
101
+ }
102
+ export {
103
+ createConfigFile,
104
+ deleteConfigDir,
105
+ deleteConfigFile,
106
+ emptyConfigObj,
107
+ ensureConfigFile,
108
+ getConfig,
109
+ getConfigFile,
110
+ parseConfigFile,
111
+ updateConfig,
112
+ validateConfigObj
113
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxfb/tools",
3
- "version": "0.0.43",
3
+ "version": "0.2.3",
4
4
  "description": "",
5
5
  "author": "Maxime Fabas",
6
6
  "license": "ISC",
@@ -11,32 +11,31 @@
11
11
  "type": "module",
12
12
  "main": "index.js",
13
13
  "module": "index.js",
14
- "dependencies": {},
15
14
  "peerDependencies": {
15
+ "@design-edito/tools": "^0.1.73",
16
16
  "chalk": "^5.3.0",
17
17
  "fs-extra": "^11.2.0",
18
- "get-image-colors": "^4.0.1",
19
- "jsdom": "^24.0.0",
18
+ "jsdom": "^24.1.1",
20
19
  "node-fetch": "^3.3.2",
21
- "react": "^18.2.0",
22
- "react-dom": "^18.2.0",
20
+ "react": "^18.3.1",
21
+ "react-dom": "^18.3.1",
23
22
  "sharp": "^0.33.3"
24
23
  },
25
24
  "devDependencies": {
26
- "@types/chalk": "^2.2.0",
27
- "@types/fs-extra": "^11.0.4",
28
- "@types/get-image-colors": "^4.0.5",
29
- "@types/jsdom": "^21.1.6",
30
- "@types/node": "^20.12.5",
25
+ "@types/node": "^22.15.21",
31
26
  "@types/prompts": "^2.4.9",
32
- "@types/react": "^18.2.74",
33
- "@types/react-dom": "^18.2.24",
34
- "@types/semver": "^7.5.8",
35
- "camelcase": "^8.0.0",
36
- "esbuild": "^0.20.2",
27
+ "@types/semver": "^7.7.0",
28
+ "chalk": "^5.4.1",
29
+ "chokidar-cli": "^3.0.0",
30
+ "concurrently": "^9.1.2",
31
+ "esbuild": "^0.25.5",
37
32
  "prompts": "^2.4.2",
38
- "semver": "^7.6.0",
39
- "simple-git": "^3.24.0",
40
- "typescript": "^5.4.4"
33
+ "puppeteer": "^24.9.0",
34
+ "react": "^19.1.0",
35
+ "react-dom": "^19.1.0",
36
+ "semver": "^7.7.2",
37
+ "sharp": "^0.34.2",
38
+ "simple-git": "^3.27.0",
39
+ "typescript": "^5.8.3"
41
40
  }
42
41
  }