@dicelette/core 1.1.4 → 1.2.1

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.d.mts CHANGED
@@ -1,57 +1,182 @@
1
1
  declare const COMMENT_REGEX: RegExp;
2
+ /**
3
+ * Parse the string provided and turn it as a readable dice for dice parser
4
+ * @param dice {string}
5
+ */
2
6
  declare function roll(dice: string): Resultat | undefined;
7
+ /**
8
+ * Evaluate a formula and replace "^" by "**" if any
9
+ * @param {Sign} sign
10
+ * @param {number} value
11
+ * @param {number} total
12
+ * @returns
13
+ */
3
14
  declare function calculator(sign: Sign, value: number, total: number): number;
4
15
 
5
16
  interface Resultat {
17
+ /**
18
+ * Original dice throw
19
+ */
6
20
  dice: string;
21
+ /**
22
+ * Result of the dice throw
23
+ */
7
24
  result: string;
25
+ /**
26
+ * The comment that was added to the dice throw (if any)
27
+ */
8
28
  comment?: string;
29
+ /**
30
+ * The comparison made on the dice
31
+ */
9
32
  compare?: Compare | undefined;
33
+ /**
34
+ * If any value was added to the dice throw
35
+ */
10
36
  modifier?: Modifier;
11
37
  }
12
38
  interface Compare {
39
+ /**
40
+ * Sign of the comparison
41
+ */
13
42
  sign: "<" | ">" | ">=" | "<=" | "=" | "!=" | "==";
43
+ /**
44
+ * Value of the comparison
45
+ */
14
46
  value: number;
15
47
  }
48
+ /**
49
+ * Sign format for calculation of modifier
50
+ */
16
51
  type Sign = "+" | "-" | "*" | "/" | "%" | "^" | "**";
17
52
  interface Modifier {
53
+ /**
54
+ * Sign of the modifier
55
+ */
18
56
  sign?: Sign;
57
+ /**
58
+ * Value of the modifier
59
+ */
19
60
  value: number;
20
61
  }
62
+ /**
63
+ * Statistic object template
64
+ */
21
65
  type Statistic = {
22
66
  [name: string]: {
67
+ /**
68
+ * The value of the statistic that can take the stats
69
+ */
23
70
  max?: number;
71
+ /**
72
+ * The minimal value of the statistic that can take the stats
73
+ */
24
74
  min?: number;
75
+ /**
76
+ * The combinaison that can be made with ANOTHER statistic
77
+ * Automatically disable the max/min value
78
+ */
25
79
  combinaison?: string;
26
80
  };
27
81
  };
82
+ /**
83
+ * @example
84
+ * diceType: 1d20+$>=20
85
+ * The dice throw will be 1d20 + statistique that must be >= 20
86
+ * @example
87
+ * diceType: 1d20<=$
88
+ * The dice throw will be 1d20 that must be <= statistique
89
+ */
28
90
  interface StatisticalTemplate {
91
+ /** Allow to force the user to choose a name for them characters */
29
92
  charName?: boolean;
30
93
  statistics?: Statistic;
94
+ /**
95
+ * A total can be set, it allows to calculate the total value of a future register member
96
+ * If the sum of the value > total, the bot will send a message to the user to inform him that the total is exceeded and an error will be thrown
97
+ * @note statistique that have a formula will be ignored from the total
98
+ */
31
99
  total?: number;
100
+ /** A dice type in the notation supported by the bot */
32
101
  diceType?: string;
102
+ /**
103
+ * How the success/echec will be done
104
+ */
33
105
  critical?: Critical;
106
+ /** Special dice for damage */
34
107
  damage?: {
35
108
  [name: string]: string;
36
109
  };
37
110
  }
111
+ /**
112
+ * If the result can be considered as a critical
113
+ * Critical is compared to the "natural" dice result, so any modifier doesn't count
114
+ */
38
115
  interface Critical {
116
+ /**
117
+ * The value that will be considered as a success
118
+ */
39
119
  success?: number;
120
+ /**
121
+ * The value that will be considered as a failure
122
+ */
40
123
  failure?: number;
41
124
  }
42
125
 
126
+ /**
127
+ * Escape regex string
128
+ * @param string {string}
129
+ */
43
130
  declare function escapeRegex(string: string): string;
131
+ /**
132
+ * Replace the stat name by their value using stat and after evaluate any formula using `replaceFormulaInDice`
133
+ * @param originalDice {dice}
134
+ * @param stats {[name: string]: number}
135
+ */
44
136
  declare function generateStatsDice(originalDice: string, stats?: {
45
137
  [name: string]: number;
46
138
  }): string;
139
+ /**
140
+ * Replace the {{}} in the dice string and evaluate the interior if any
141
+ * @param dice {string}
142
+ */
47
143
  declare function replaceFormulaInDice(dice: string): string;
144
+ /**
145
+ * Replace the ++ +- -- by their proper value:
146
+ * - `++` = `+`
147
+ * - `+-` = `-`
148
+ * - `--` = `+`
149
+ * @param dice {string}
150
+ */
48
151
  declare function cleanedDice(dice: string): string;
49
152
 
153
+ /**
154
+ * Verify if the provided dice work with random value
155
+ * @param testDice {string}
156
+ * @param stats {[name: string]: number}
157
+ */
50
158
  declare function evalStatsDice(testDice: string, stats?: {
51
159
  [name: string]: number;
52
160
  }): string;
161
+ /**
162
+ * Generate a random dice and remove the formula (+ evaluate it)
163
+ * Used for diceDamage only
164
+ * @param value {string}
165
+ * @param template {StatisticalTemplate}
166
+ * @returns
167
+ */
53
168
  declare function diceRandomParse(value: string, template: StatisticalTemplate): string;
169
+ /**
170
+ * Same as damageDice but for DiceType
171
+ * @param dice {string}
172
+ * @param template {StatisticalTemplate}
173
+ */
54
174
  declare function diceTypeRandomParse(dice: string, template: StatisticalTemplate): string;
175
+ /**
176
+ * Random the combinaison and evaluate it to check if everything is valid
177
+ * @param combinaison {[name: string]: string}
178
+ * @param stats {[name: string]: string|number}
179
+ */
55
180
  declare function evalCombinaison(combinaison: {
56
181
  [name: string]: string;
57
182
  }, stats: {
@@ -59,12 +184,72 @@ declare function evalCombinaison(combinaison: {
59
184
  }): {
60
185
  [name: string]: number;
61
186
  };
187
+ /**
188
+ * Evaluate one selected combinaison
189
+ * @param combinaison {string}
190
+ * @param stats {[name: string]: string|number}
191
+ */
62
192
  declare function evalOneCombinaison(combinaison: string, stats: {
63
193
  [name: string]: string | number;
64
194
  }): any;
195
+ /**
196
+ * Parse the provided JSON and verify each field to check if everything could work when rolling
197
+ * @param {any} template
198
+ * @returns {StatisticalTemplate}
199
+ */
65
200
  declare function verifyTemplateValue(template: any): StatisticalTemplate;
201
+ /**
202
+ * Test each damage roll from the template.damage
203
+ * @param {StatisticalTemplate} template
204
+ */
66
205
  declare function testDiceRegistered(template: StatisticalTemplate): void;
206
+ /**
207
+ * Test all combinaison with generated random value
208
+ * @param {StatisticalTemplate} template
209
+ */
67
210
  declare function testStatCombinaison(template: StatisticalTemplate): void;
211
+ /**
212
+ * Generate a random stat based on the template and the statistical min and max
213
+ * @param {number|undefined} total
214
+ * @param {number | undefined} max
215
+ * @param {number | undefined} min
216
+ * @returns
217
+ */
68
218
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number): number;
69
219
 
70
- export { COMMENT_REGEX, type Compare, type Critical, type Modifier, type Resultat, type Sign, type Statistic, type StatisticalTemplate, calculator, cleanedDice, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, replaceFormulaInDice, roll, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
220
+ declare class DiceTypeError extends Error {
221
+ readonly dice: string;
222
+ readonly cause: string | undefined;
223
+ readonly method: unknown;
224
+ constructor(dice: string, cause?: string, method?: unknown);
225
+ }
226
+ declare class FormulaError extends Error {
227
+ readonly formula: string;
228
+ readonly cause: string | undefined;
229
+ readonly method: unknown;
230
+ constructor(formula: string, cause?: string, method?: unknown);
231
+ }
232
+ declare class MaxGreater extends Error {
233
+ readonly name: string;
234
+ readonly value: number;
235
+ readonly max: number;
236
+ constructor(value: number, max: number);
237
+ }
238
+ declare class EmptyObjectError extends Error {
239
+ readonly name: string;
240
+ constructor();
241
+ }
242
+ declare class TooManyDice extends Error {
243
+ readonly name: string;
244
+ constructor();
245
+ }
246
+ declare class TooManyStats extends Error {
247
+ readonly name: string;
248
+ constructor();
249
+ }
250
+ declare class NoStatisticsError extends Error {
251
+ readonly name: string;
252
+ constructor();
253
+ }
254
+
255
+ export { COMMENT_REGEX, type Compare, type Critical, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, type Sign, type Statistic, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, cleanedDice, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, replaceFormulaInDice, roll, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
package/dist/index.d.ts CHANGED
@@ -1,57 +1,182 @@
1
1
  declare const COMMENT_REGEX: RegExp;
2
+ /**
3
+ * Parse the string provided and turn it as a readable dice for dice parser
4
+ * @param dice {string}
5
+ */
2
6
  declare function roll(dice: string): Resultat | undefined;
7
+ /**
8
+ * Evaluate a formula and replace "^" by "**" if any
9
+ * @param {Sign} sign
10
+ * @param {number} value
11
+ * @param {number} total
12
+ * @returns
13
+ */
3
14
  declare function calculator(sign: Sign, value: number, total: number): number;
4
15
 
5
16
  interface Resultat {
17
+ /**
18
+ * Original dice throw
19
+ */
6
20
  dice: string;
21
+ /**
22
+ * Result of the dice throw
23
+ */
7
24
  result: string;
25
+ /**
26
+ * The comment that was added to the dice throw (if any)
27
+ */
8
28
  comment?: string;
29
+ /**
30
+ * The comparison made on the dice
31
+ */
9
32
  compare?: Compare | undefined;
33
+ /**
34
+ * If any value was added to the dice throw
35
+ */
10
36
  modifier?: Modifier;
11
37
  }
12
38
  interface Compare {
39
+ /**
40
+ * Sign of the comparison
41
+ */
13
42
  sign: "<" | ">" | ">=" | "<=" | "=" | "!=" | "==";
43
+ /**
44
+ * Value of the comparison
45
+ */
14
46
  value: number;
15
47
  }
48
+ /**
49
+ * Sign format for calculation of modifier
50
+ */
16
51
  type Sign = "+" | "-" | "*" | "/" | "%" | "^" | "**";
17
52
  interface Modifier {
53
+ /**
54
+ * Sign of the modifier
55
+ */
18
56
  sign?: Sign;
57
+ /**
58
+ * Value of the modifier
59
+ */
19
60
  value: number;
20
61
  }
62
+ /**
63
+ * Statistic object template
64
+ */
21
65
  type Statistic = {
22
66
  [name: string]: {
67
+ /**
68
+ * The value of the statistic that can take the stats
69
+ */
23
70
  max?: number;
71
+ /**
72
+ * The minimal value of the statistic that can take the stats
73
+ */
24
74
  min?: number;
75
+ /**
76
+ * The combinaison that can be made with ANOTHER statistic
77
+ * Automatically disable the max/min value
78
+ */
25
79
  combinaison?: string;
26
80
  };
27
81
  };
82
+ /**
83
+ * @example
84
+ * diceType: 1d20+$>=20
85
+ * The dice throw will be 1d20 + statistique that must be >= 20
86
+ * @example
87
+ * diceType: 1d20<=$
88
+ * The dice throw will be 1d20 that must be <= statistique
89
+ */
28
90
  interface StatisticalTemplate {
91
+ /** Allow to force the user to choose a name for them characters */
29
92
  charName?: boolean;
30
93
  statistics?: Statistic;
94
+ /**
95
+ * A total can be set, it allows to calculate the total value of a future register member
96
+ * If the sum of the value > total, the bot will send a message to the user to inform him that the total is exceeded and an error will be thrown
97
+ * @note statistique that have a formula will be ignored from the total
98
+ */
31
99
  total?: number;
100
+ /** A dice type in the notation supported by the bot */
32
101
  diceType?: string;
102
+ /**
103
+ * How the success/echec will be done
104
+ */
33
105
  critical?: Critical;
106
+ /** Special dice for damage */
34
107
  damage?: {
35
108
  [name: string]: string;
36
109
  };
37
110
  }
111
+ /**
112
+ * If the result can be considered as a critical
113
+ * Critical is compared to the "natural" dice result, so any modifier doesn't count
114
+ */
38
115
  interface Critical {
116
+ /**
117
+ * The value that will be considered as a success
118
+ */
39
119
  success?: number;
120
+ /**
121
+ * The value that will be considered as a failure
122
+ */
40
123
  failure?: number;
41
124
  }
42
125
 
126
+ /**
127
+ * Escape regex string
128
+ * @param string {string}
129
+ */
43
130
  declare function escapeRegex(string: string): string;
131
+ /**
132
+ * Replace the stat name by their value using stat and after evaluate any formula using `replaceFormulaInDice`
133
+ * @param originalDice {dice}
134
+ * @param stats {[name: string]: number}
135
+ */
44
136
  declare function generateStatsDice(originalDice: string, stats?: {
45
137
  [name: string]: number;
46
138
  }): string;
139
+ /**
140
+ * Replace the {{}} in the dice string and evaluate the interior if any
141
+ * @param dice {string}
142
+ */
47
143
  declare function replaceFormulaInDice(dice: string): string;
144
+ /**
145
+ * Replace the ++ +- -- by their proper value:
146
+ * - `++` = `+`
147
+ * - `+-` = `-`
148
+ * - `--` = `+`
149
+ * @param dice {string}
150
+ */
48
151
  declare function cleanedDice(dice: string): string;
49
152
 
153
+ /**
154
+ * Verify if the provided dice work with random value
155
+ * @param testDice {string}
156
+ * @param stats {[name: string]: number}
157
+ */
50
158
  declare function evalStatsDice(testDice: string, stats?: {
51
159
  [name: string]: number;
52
160
  }): string;
161
+ /**
162
+ * Generate a random dice and remove the formula (+ evaluate it)
163
+ * Used for diceDamage only
164
+ * @param value {string}
165
+ * @param template {StatisticalTemplate}
166
+ * @returns
167
+ */
53
168
  declare function diceRandomParse(value: string, template: StatisticalTemplate): string;
169
+ /**
170
+ * Same as damageDice but for DiceType
171
+ * @param dice {string}
172
+ * @param template {StatisticalTemplate}
173
+ */
54
174
  declare function diceTypeRandomParse(dice: string, template: StatisticalTemplate): string;
175
+ /**
176
+ * Random the combinaison and evaluate it to check if everything is valid
177
+ * @param combinaison {[name: string]: string}
178
+ * @param stats {[name: string]: string|number}
179
+ */
55
180
  declare function evalCombinaison(combinaison: {
56
181
  [name: string]: string;
57
182
  }, stats: {
@@ -59,12 +184,72 @@ declare function evalCombinaison(combinaison: {
59
184
  }): {
60
185
  [name: string]: number;
61
186
  };
187
+ /**
188
+ * Evaluate one selected combinaison
189
+ * @param combinaison {string}
190
+ * @param stats {[name: string]: string|number}
191
+ */
62
192
  declare function evalOneCombinaison(combinaison: string, stats: {
63
193
  [name: string]: string | number;
64
194
  }): any;
195
+ /**
196
+ * Parse the provided JSON and verify each field to check if everything could work when rolling
197
+ * @param {any} template
198
+ * @returns {StatisticalTemplate}
199
+ */
65
200
  declare function verifyTemplateValue(template: any): StatisticalTemplate;
201
+ /**
202
+ * Test each damage roll from the template.damage
203
+ * @param {StatisticalTemplate} template
204
+ */
66
205
  declare function testDiceRegistered(template: StatisticalTemplate): void;
206
+ /**
207
+ * Test all combinaison with generated random value
208
+ * @param {StatisticalTemplate} template
209
+ */
67
210
  declare function testStatCombinaison(template: StatisticalTemplate): void;
211
+ /**
212
+ * Generate a random stat based on the template and the statistical min and max
213
+ * @param {number|undefined} total
214
+ * @param {number | undefined} max
215
+ * @param {number | undefined} min
216
+ * @returns
217
+ */
68
218
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number): number;
69
219
 
70
- export { COMMENT_REGEX, type Compare, type Critical, type Modifier, type Resultat, type Sign, type Statistic, type StatisticalTemplate, calculator, cleanedDice, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, replaceFormulaInDice, roll, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
220
+ declare class DiceTypeError extends Error {
221
+ readonly dice: string;
222
+ readonly cause: string | undefined;
223
+ readonly method: unknown;
224
+ constructor(dice: string, cause?: string, method?: unknown);
225
+ }
226
+ declare class FormulaError extends Error {
227
+ readonly formula: string;
228
+ readonly cause: string | undefined;
229
+ readonly method: unknown;
230
+ constructor(formula: string, cause?: string, method?: unknown);
231
+ }
232
+ declare class MaxGreater extends Error {
233
+ readonly name: string;
234
+ readonly value: number;
235
+ readonly max: number;
236
+ constructor(value: number, max: number);
237
+ }
238
+ declare class EmptyObjectError extends Error {
239
+ readonly name: string;
240
+ constructor();
241
+ }
242
+ declare class TooManyDice extends Error {
243
+ readonly name: string;
244
+ constructor();
245
+ }
246
+ declare class TooManyStats extends Error {
247
+ readonly name: string;
248
+ constructor();
249
+ }
250
+ declare class NoStatisticsError extends Error {
251
+ readonly name: string;
252
+ constructor();
253
+ }
254
+
255
+ export { COMMENT_REGEX, type Compare, type Critical, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, type Sign, type Statistic, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, cleanedDice, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, replaceFormulaInDice, roll, testDiceRegistered, testStatCombinaison, verifyTemplateValue };