@dicelette/core 1.20.0 → 1.20.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/README.md CHANGED
@@ -1,208 +1,202 @@
1
1
  # @Core
2
2
 
3
- The core module for Dicelette, contains :
4
- - The dice function (that parse the string into a Dice Parser and send the result in a good message) ;
5
- - The verification of the template
3
+ The core module for Dicelette public API reference
6
4
 
7
- The two are used in the bot and documentation.
5
+ This README documents the public API exported by the `core` package. It lists types, constants, functions and errors that are exported by the module (via `src/index.ts`).
8
6
 
9
- # Type alias
10
- - **Sign**: `"+" | "-" | "*" | "/" | "%" | "^" | "**";`
11
- - **Statistic** : `{ [name: string]: { combinaison?: string; max?: number; min?: number; } }` :
12
- - **name**: `string` : The name of the statistic
13
- - **combinaison**: `string` : A combinaison between multiple/other statistic, formula... (ex: `constitution+2`). Can't coexist with min & max.
14
- - **max**: `number` : The maximum value of the statistic
15
- - **min**: `number` : The minimum value of the statistic
7
+ ## Overview
16
8
 
17
- # Interface ([index.d.ts](@types/index.d.ts))
18
- ## Compare
9
+ The `core` module provides small utilities to parse and evaluate dice notation, to generate and replace statistical values in dice expressions, and to validate statistical templates. The API is intended to be consumed by higher-level modules (bot, CLI, etc.).
19
10
 
20
- - **sign**: ``"<"`` \| ``">"`` \| ``">="`` \| ``"<="`` \| ``"="`` \| ``"!="`` \| ``"=="``
21
- - **value**: `number`
11
+ ## Public API
22
12
 
23
- ## Critical
13
+ Note: when a parameter `engine` is shown it usually defaults to the `NumberGenerator.engines.nodeCrypto` engine (from `@dice-roller/rpg-dice-roller`) unless otherwise specified.
24
14
 
25
- - `Optional` **failure**: `number`
26
- - `Optional` **success**: `number`
15
+ ### Interfaces & Types (from `src/interfaces`)
27
16
 
28
- ## Modifier
17
+ #### Interface: Resultat
18
+ - dice: string — Original dice throw
19
+ - result: string — Formatted result from the dice roller
20
+ - comment?: string — Optional comment attached to the dice
21
+ - compare?: ComparedValue — Optional comparison attached to the roll
22
+ - modifier?: Modifier — Optional modifier applied to the roll
23
+ - total?: number — Optional numeric total of the roll
29
24
 
30
- - **sign**: [Sign](#sign)
31
- - **value**: `number`
25
+ #### Interface: Compare
26
+ - sign: "<" | ">" | ">=" | "<=" | "=" | "!=" | "=="
27
+ - value: number
32
28
 
33
- ## Resultat
29
+ #### Type: Sign
30
+ - `"+" | "-" | "*" | "/" | "%" | "^" | "**"` — Used for modifiers calculation
34
31
 
35
- - `Optional` **comment**: `string`
36
- - `Optional` **compare**: [`Compare`](#compare)
37
- - **dice**: `string`
38
- - `Optional` **modifier**: [`Modifier`](#modifier)
39
- - **result**: `string`
32
+ #### Type: ComparedValue
33
+ - `Compare & { originalDice?: string; rollValue?: string }` Extends `Compare` with optional original dice and roll output when comparison uses a dice expression
40
34
 
41
- ## Statistical Template
42
- ### Example
35
+ #### Interface: Modifier
36
+ - sign?: Sign
37
+ - value: number
43
38
 
44
- ```ts
45
- diceType: "1d20+{{$}}>=20"
46
- ```
47
- The dice throw will be 1d20 + statistique that must be less than 20
39
+ #### Type: Statistic
40
+ - Record<string, StatEntry> — map of statistic name to options (see `StatisticalTemplate`)
48
41
 
49
- ```ts
50
- diceType: "1d20<=$"
51
- ```
52
- The dice throw will be 1d20 that must be less than the statistic
42
+ #### Interface: StatisticalTemplate
43
+ - charName?: boolean — force character name selection
44
+ - statistics?: Statistic — statistics available for a template
45
+ - total?: number optional total for distribution checks
46
+ - forceDistrib?: boolean — force distribution
47
+ - diceType?: string — dice expression for rolls
48
+ - critical?: Critical — numerical critical settings
49
+ - customCritical?: CustomCriticalMap — map of custom critical rules
50
+ - damage?: Record<string, string> — named damage dice expressions
53
51
 
54
- ### Properties
55
- - `Optional` **charName**: `boolean`
56
- Allow to force the user to choose a name for them characters
52
+ #### Interface: Critical
53
+ - success?: number
54
+ - failure?: number
57
55
 
58
- - `Optional` **critical**: [`Critical`](#critical)
59
- How the success/echec will be done
56
+ #### Type: CustomCriticalMap
57
+ - `Record<string, CustomCritical>`
60
58
 
61
- - `Optional` **damage**: `{ [name: string]: string }`
62
- Special dice for damage
59
+ #### Interface: CustomCritical
60
+ - sign: "<" | ">" | "<=" | ">=" | "!=" | "=="
61
+ - value: string — can be a numeric string or a formula (may include `$` for statistic insertion)
62
+ - onNaturalDice?: boolean
63
+ - affectSkill?: boolean
63
64
 
64
- - `Optional` **diceType**: `string`
65
- A die type in the notation supported by the bot. [See documentation for syntaxe](https://dicelette.github.io/en/docs/model/register).
65
+ ### Constants (from `src/interfaces/constant.ts`)
66
66
 
67
- - `Optional` **statistics**: [`Statistic`](#statistic-type)
67
+ #### Constant: COMMENT_REGEX
68
+ - RegExp — regex used to capture inline comments in a dice expression
68
69
 
69
- - `Optional` **total**: `number`
70
- A total can be set, it allows to calculate the total value of a future register member
71
- 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
72
- Note: Statistic that have a formula will be ignored from the total
70
+ #### Constant: SIGN_REGEX
71
+ - RegExp regex matching comparison signs (`>`, `<`, `>=`, `<=`, `==`, `!=`, etc.)
73
72
 
74
- # Modules
75
- ## Dice
73
+ #### Constant: SIGN_REGEX_SPACE
74
+ - RegExp — regex matching comparison sign and following token
76
75
 
77
- ### Variables
78
- - `const` **COMMENT_REGEX**: `RegExp`
76
+ #### Constant: SYMBOL_DICE
77
+ - string symbol used to reference previous dice result inside shared rolls (value: `"&"`)
79
78
 
80
- ### Functions
81
- #### **calculator**(`sign`, `value`, `total`): `number`
82
- Evaluate a formula and replace "^" by "**" if any
79
+ #### Constant: DETECT_CRITICAL
80
+ - RegExp regex pattern used to detect inlined critical markers in dice type strings
83
81
 
84
- | Name | Type |
85
- | :------ | :------ |
86
- | `sign` | [`Sign`](#sign) |
87
- | `value` | `number` |
88
- | `total` | `number` |
82
+ ### Utility functions (`src/utils.ts`)
89
83
 
90
- #### **roll**(`dice`): [`Resultat`](#resultat) `| undefined`
91
- Parse the string provided and turn it as a readable dice for dice parser
84
+ #### Function: escapeRegex(string: string): string
85
+ - Escape input string to be used in a RegExp.
92
86
 
93
- | Name | Type | Description |
94
- | :------ | :------ | :------ |
95
- | `dice` | `string` | {string} |
87
+ #### Function: standardizeDice(dice: string): string
88
+ - Standardizes dice notation while preserving bracketed text.
96
89
 
90
+ #### Function: generateStatsDice(originalDice: string, stats?: Record<string, number>, dollarValue?: string): string
91
+ - Replace statistic names with numeric values from `stats` and evaluate `{{ }}` formulas.
92
+ - If `dollarValue` is provided, all `$` placeholders are replaced by it before formula evaluation.
97
93
 
98
- ## Utils
99
- ### **cleanedDice**(`dice`): `string`
94
+ #### Function: replaceFormulaInDice(dice: string): string
95
+ - Finds `{{ ... }}` tokens in a dice string and evaluates their content using `mathjs`.
96
+ - Throws `FormulaError` on invalid expression.
100
97
 
101
- Replace the ++ +- -- by their proper value:
102
- - `++` = `+`
103
- - `+-` = `-`
104
- - `--` = `+`
98
+ #### Function: isNumber(value: unknown): boolean
99
+ - Returns `true` if `value` is a number or numeric string.
105
100
 
106
- | Name | Type | Description |
107
- | :------ | :------ | :------ |
108
- | `dice` | `string` | {string} |
101
+ #### Function: replaceExpByRandom(dice: string, engine?: Engine | null): string
102
+ - Replaces `{exp}` placeholders by a random integer between 1 and 999 or a default value if provided (`{exp || 10}`). Uses `random-js` engine.
109
103
 
110
- ### **escapeRegex**(`string`): `string`
111
- Escape regex string
104
+ #### Function: randomInt(min: number, max: number, engine?: Engine | null): number
105
+ - Returns a random integer between `min` and `max` using `random-js` and the provided engine.
112
106
 
113
- | Name | Type | Description |
114
- | :------ | :------ | :------ |
115
- | `string` | `string` | {string} |
107
+ #### Function: getEngineId(engine: unknown): string
108
+ - Returns a human readable id for a `NumberGenerator` engine, e.g. `nodeCrypto`, `nativeMath`, `browserCrypto`, or fallbacks like constructor name.
116
109
 
117
- ### **generateStatsDice**(`originalDice`, `stats?`): `string`
110
+ #### Function: getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine
111
+ - Returns the engine instance (from `NumberGenerator.engines`) matching the provided name.
118
112
 
119
- Replace the stat name by their value using stat and after evaluate any formula using `replaceFormulaInDice`
113
+ ### Dice functions (`src/dice.ts`)
120
114
 
121
- | Name | Type | Description |
122
- | :------ | :------ | :------ |
123
- | `originalDice` | `string` | {dice} |
124
- | `stats?` | `Object` | {[name: string]: number} |
115
+ #### Function: roll(dice: string, engine?: Engine | null): Resultat | undefined
116
+ - Parse a dice notation string and perform the roll(s) using `rpg-dice-roller`.
117
+ - Supports comments, grouped/shared rolls, comparisons, modifiers and custom notation (see module docs).
118
+ - Returns `Resultat` when a dice expression is recognized, otherwise `undefined`.
119
+ - Throws `DiceTypeError` when the expression cannot be parsed or rolled.
125
120
 
126
- ### **replaceFormulaInDice**(`dice`, `stats`): `string`
121
+ #### Function: calculator(sign: Sign, value: number, total: number): number
122
+ - Evaluate a simple binary operation between `total` and `value` using the `sign` (supports `^` which is normalized to `**`). Uses `mathjs` to compute.
127
123
 
128
- Replace the {{}} in the dice string and evaluate the interior if any
124
+ #### Function: createCriticalCustom(dice: string, customCritical: CustomCritical, template: StatisticalTemplate, engine?: Engine | null): string
125
+ - Create and return a dice expression where the template's `$` placeholders and formulas are evaluated for a custom critical rule.
126
+ - Throws `DiceTypeError` if the generated comparison contains `$` (not resolved) or if underlying dice parsing fails.
129
127
 
130
- | Name | Type | Description |
131
- | :------ | :------ | :------ |
132
- | `dice` | `string` | {string} |
128
+ ### Template verification (`src/verify_template.ts`)
133
129
 
130
+ #### Function: evalStatsDice(testDice: string, allStats?: Record<string, number>, engine?: Engine | null): string
131
+ - Replace statistic names in `testDice` with provided `allStats`, evaluate formulas / `{exp}` and verify the expression can be rolled.
132
+ - Returns the original `testDice` if validation passes, otherwise throws `DiceTypeError`.
134
133
 
135
- ## Verify Template
136
- ### **diceRandomParse**(`value`, `template`): `string`
134
+ #### Function: diceRandomParse(value: string, template: StatisticalTemplate, engine?: Engine | null): string
135
+ - For a damage dice expression (or similar), randomly choose a statistic value from `template.statistics` and replace statistic names, then evaluate `{{ }}` formulas.
137
136
 
138
- Generate a random dice and remove the formula (+ evaluate it)
139
- Used for diceDamage only
137
+ #### Function: diceTypeRandomParse(dice: string, template: StatisticalTemplate, engine?: Engine | null): string
138
+ - For a `diceType` expression, picks one statistic (non-combination) from `template.statistics`, generates a random value and replaces `$` placeholders. Also replaces `{exp}` placeholders.
140
139
 
141
- | Name | Type | Description |
142
- | :------ | :------ | :------ |
143
- | `value` | `string` | {string} |
144
- | `template` | [`StatisticalTemplate`](#statistical-template) | {StatisticalTemplate} |
140
+ #### Function: evalCombinaison(combinaison: Record<string,string>, stats: Record<string, number | string>): Record<string, number>
141
+ - For each entry in `combinaison`, replace referenced stats and evaluate the formula to produce numeric values.
142
+ - Throws `FormulaError` on invalid formula.
145
143
 
146
- ### **diceTypeRandomParse**(`dice`, `template`): `string`
147
- | Name | Type | Description |
148
- | :------ | :------ | :------ |
149
- | `dice` | `string` | {string} |
150
- | `template` | [`StatisticalTemplate`](#statistical-template) | {StatisticalTemplate} |
144
+ #### Function: evalOneCombinaison(combinaison: string, stats: Record<string, number | string>): any
145
+ - Replace stats in the single `combinaison` string and evaluate; returns the evaluation result or throws `FormulaError`.
151
146
 
152
- ### **evalCombinaison**(`combinaison`, `stats`): `Object`
153
- Random the combinaison and evaluate it to check if everything is valid
147
+ #### Function: verifyTemplateValue(template: unknown, verify?: boolean, engine?: Engine | null): StatisticalTemplate
148
+ - Parse and validate a raw template object using Zod `templateSchema`. Convert some fields (like critical success/failure) to numbers.
149
+ - If `verify` is true it runs extra verification (rolls `diceType` expressions, tests custom criticals, registered damages and stat combinations) and throws domain errors if invalid.
150
+ - Returns a typed `StatisticalTemplate` on success.
154
151
 
155
- | Name | Type | Description |
156
- | :------ | :------ | :------ |
157
- | `combinaison` | `Object` | {[name: string]: string} |
158
- | `stats` | `Object` | {[name: string]: string\|number} |
152
+ #### Function: testDiceRegistered(template: StatisticalTemplate, engine?: Engine | null): void
153
+ - Validate `template.damage` entries by generating random dice and attempting to roll them. Throws `DiceTypeError` or domain errors for invalid entries.
159
154
 
160
- ### **evalOneCombinaison**(`combinaison`, `stats`): `any`
155
+ #### Function: testStatCombinaison(template: StatisticalTemplate, engine?: Engine | null): void
156
+ - Validates `statistics` that are combination formulas (`combinaison`) by generating random backing stats and evaluating each formula.
161
157
 
162
- Evaluate one selected combinaison
158
+ #### Function: generateRandomStat(total?: number, max?: number, min?: number, engine?: Engine | null): number
159
+ - Generate a single random statistic value honoring optional `min` / `max` and `total` constraints; repeats until a valid value is found.
163
160
 
164
- | Name | Type | Description |
165
- | :------ | :------ | :------ |
166
- | `combinaison` | `string` | {string} |
167
- | `stats` | `Object` | {[name: string]: string\|number} |
161
+ ### Errors (from `src/errors.ts`)
168
162
 
169
- ### **evalStatsDice**(`testDice`, `stats?`): `string`
163
+ #### Error class: DiceTypeError
164
+ - extends `Error`
165
+ - Properties: `dice: string`, `cause?: string`, `method?: unknown`
166
+ - Thrown when a dice expression cannot be parsed or rolled; used widely across the module.
170
167
 
171
- Verify if the provided dice work with random value
168
+ #### Error class: FormulaError
169
+ - extends `Error`
170
+ - Properties: `formula: string`, `cause?: string`, `method?: unknown`
171
+ - Thrown when a formula (e.g. inside `{{ }}` or a combinaison) cannot be evaluated.
172
172
 
173
- | Name | Type | Description |
174
- | :------ | :------ | :------ |
175
- | `testDice` | `string` | {string} |
176
- | `stats?` | `Object` | {[name: string]: number} |
173
+ #### Error class: MaxGreater
174
+ - extends `Error`
175
+ - Properties: `name: string`, `value: number`, `max: number`
176
+ - Thrown by schema refinement when `max` <= `min`.
177
177
 
178
- ### **generateRandomStat**(`total?`, `max?`, `min?`): `number`
178
+ #### Error class: EmptyObjectError
179
+ - extends `Error` — Thrown when an object expected to be non-empty is empty.
179
180
 
180
- | Name | Type | Default value |
181
- | :------ | :------ | :------ |
182
- | `total` | `undefined` \| `number` | `100` |
183
- | `max?` | `number` | `undefined` |
184
- | `min?` | `number` | `undefined` |
181
+ #### Error class: TooManyDice
182
+ - extends `Error` Thrown when too many damage dice entries are present.
185
183
 
186
- ### **testCombinaison**(`template`): `void`
184
+ #### Error class: TooManyStats
185
+ - extends `Error` — Thrown when too many statistics are provided.
187
186
 
188
- Test all combinaison with generated random value
187
+ #### Error class: NoStatisticsError
188
+ - extends `Error` — Thrown when combinaison validation requires base statistics but none are present.
189
189
 
190
- | Name | Type |
191
- | :------ | :------ |
192
- | `template` | [`StatisticalTemplate`](#statistical-template) |
190
+ ### Zod Schema (from `src/interfaces/zod.ts`)
193
191
 
194
- ### **testDamageRoll**(`template`): `void`
192
+ #### Export: templateSchema
193
+ - Zod schema for `StatisticalTemplate` JSON: `charName`, `statistics`, `total`, `forceDistrib`, `diceType`, `critical`, `customCritical`, `damage`.
194
+ - Use `templateSchema.parse(obj)` to validate raw JSON and obtain transformed values.
195
195
 
196
- Test each damage roll from the template.damage
196
+ ### Usage notes
197
197
 
198
- | Name | Type |
199
- | :------ | :------ |
200
- | `template` | [`StatisticalTemplate`](#statistical-template) |
198
+ - Most functions accept an optional `engine` parameter to control random number generation. The engine values correspond to `NumberGenerator.engines` from `@dice-roller/rpg-dice-roller` (e.g. `nodeCrypto`, `nativeMath`, `browserCrypto`). Use `getEngine("nodeCrypto")` to obtain the engine instance.
201
199
 
202
- ### **verifyTemplateValue**(`template`): [`StatisticalTemplate`](#statistical-template)
200
+ - Errors thrown by this module are typed (see the `Errors` section). Catch and inspect the thrown error to determine the failure reason.
203
201
 
204
- Parse the provided JSON and verify each field to check if everything could work when rolling
205
-
206
- | Name | Type |
207
- | :------ | :------ |
208
- | `template` | `any` |
202
+ - For working examples, see the test cases in the `tests/` directory of the package.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Engine } from 'random-js';
1
+ import { Engine, Random } from 'random-js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  /**
@@ -24,6 +24,41 @@ declare function roll(dice: string, engine?: Engine | null): Resultat | undefine
24
24
  */
25
25
  declare function calculator(sign: Sign, value: number, total: number): number;
26
26
 
27
+ declare class DiceTypeError extends Error {
28
+ readonly dice: string;
29
+ readonly cause: string | undefined;
30
+ readonly method: unknown;
31
+ constructor(dice: string, cause?: string, method?: unknown);
32
+ }
33
+ declare class FormulaError extends Error {
34
+ readonly formula: string;
35
+ readonly cause: string | undefined;
36
+ readonly method: unknown;
37
+ constructor(formula: string, cause?: string, method?: unknown);
38
+ }
39
+ declare class MaxGreater extends Error {
40
+ readonly name: string;
41
+ readonly value: number;
42
+ readonly max: number;
43
+ constructor(value: number, max: number);
44
+ }
45
+ declare class EmptyObjectError extends Error {
46
+ readonly name: string;
47
+ constructor();
48
+ }
49
+ declare class TooManyDice extends Error {
50
+ readonly name: string;
51
+ constructor();
52
+ }
53
+ declare class TooManyStats extends Error {
54
+ readonly name: string;
55
+ constructor();
56
+ }
57
+ declare class NoStatisticsError extends Error {
58
+ readonly name: string;
59
+ constructor();
60
+ }
61
+
27
62
  interface Resultat {
28
63
  /**
29
64
  * Original dice throw
@@ -198,6 +233,61 @@ interface CustomCritical {
198
233
  affectSkill?: boolean;
199
234
  }
200
235
 
236
+ declare const COMMENT_REGEX: RegExp;
237
+ declare const SIGN_REGEX: RegExp;
238
+ declare const SIGN_REGEX_SPACE: RegExp;
239
+ declare const SYMBOL_DICE = "&";
240
+ declare const DETECT_CRITICAL: RegExp;
241
+
242
+ interface StatisticalSchema extends StatisticalTemplate {
243
+ /**
244
+ * Specifies the URL for the schema definition
245
+ * This property is optional and should contain a valid URI.
246
+ */
247
+ $schema?: string;
248
+ }
249
+
250
+ /**
251
+ * Definition of the Zod schema for template data
252
+ */
253
+
254
+ declare const templateSchema: z.ZodObject<{
255
+ charName: z.ZodOptional<z.ZodBoolean>;
256
+ statistics: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
257
+ max: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
258
+ min: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
259
+ combinaison: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string | undefined, string>>>;
260
+ exclude: z.ZodOptional<z.ZodBoolean>;
261
+ }, z.core.$strip>>>;
262
+ total: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
263
+ forceDistrib: z.ZodOptional<z.ZodBoolean>;
264
+ diceType: z.ZodOptional<z.ZodString>;
265
+ critical: z.ZodOptional<z.ZodPipe<z.ZodObject<{
266
+ success: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
267
+ failure: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
268
+ }, z.core.$strip>, z.ZodTransform<{
269
+ success?: string | number | undefined;
270
+ failure?: string | number | undefined;
271
+ }, {
272
+ success?: string | number | undefined;
273
+ failure?: string | number | undefined;
274
+ }>>>;
275
+ customCritical: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
276
+ sign: z.ZodEnum<{
277
+ "<": "<";
278
+ ">": ">";
279
+ ">=": ">=";
280
+ "<=": "<=";
281
+ "!=": "!=";
282
+ "==": "==";
283
+ }>;
284
+ value: z.ZodString;
285
+ onNaturalDice: z.ZodOptional<z.ZodBoolean>;
286
+ affectSkill: z.ZodOptional<z.ZodBoolean>;
287
+ }, z.core.$strip>>>;
288
+ damage: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
289
+ }, z.core.$strip>;
290
+
201
291
  /**
202
292
  * Escape regex string
203
293
  * @param string {string}
@@ -236,6 +326,22 @@ declare function isNumber(value: unknown): boolean;
236
326
  * @returns {string} the dice with the {exp} replaced by a random value
237
327
  */
238
328
  declare function replaceExpByRandom(dice: string, engine?: Engine | null): string;
329
+ /**
330
+ * Utility function to get a random integer between min and max and using the specified engine
331
+ * @param min {number}
332
+ * @param max {number}
333
+ * @param engine {Engine | null} Engine to use, default to nodeCrypto
334
+ * @param rng {Random | undefined} Random instance to use, see https://www.npmjs.com/package/random-js#usage
335
+ * @returns {number} Random integer between min and max
336
+ */
337
+ declare function randomInt(min: number, max: number, engine?: Engine | null, rng?: Random): number;
338
+ /**
339
+ * Utility function that allow to get the id of an engine
340
+ * @param engine {unknown} Engine to identify
341
+ * @returns {string} Id of the engine or "unknown"
342
+ * @private
343
+ */
344
+ declare function getEngineId(engine: unknown): string;
239
345
  /**
240
346
  * Utility function to get the engine from its name
241
347
  * @param engine {"nativeMath" | "browserCrypto" | "nodeCrypto"} The engine name
@@ -243,7 +349,6 @@ declare function replaceExpByRandom(dice: string, engine?: Engine | null): strin
243
349
  * @public
244
350
  */
245
351
  declare function getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine;
246
- declare function randomInt(min: number, max: number, engine?: Engine | null): number;
247
352
 
248
353
  /**
249
354
  * Verify if the provided dice work with random value
@@ -303,94 +408,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
303
408
  */
304
409
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
305
410
 
306
- declare class DiceTypeError extends Error {
307
- readonly dice: string;
308
- readonly cause: string | undefined;
309
- readonly method: unknown;
310
- constructor(dice: string, cause?: string, method?: unknown);
311
- }
312
- declare class FormulaError extends Error {
313
- readonly formula: string;
314
- readonly cause: string | undefined;
315
- readonly method: unknown;
316
- constructor(formula: string, cause?: string, method?: unknown);
317
- }
318
- declare class MaxGreater extends Error {
319
- readonly name: string;
320
- readonly value: number;
321
- readonly max: number;
322
- constructor(value: number, max: number);
323
- }
324
- declare class EmptyObjectError extends Error {
325
- readonly name: string;
326
- constructor();
327
- }
328
- declare class TooManyDice extends Error {
329
- readonly name: string;
330
- constructor();
331
- }
332
- declare class TooManyStats extends Error {
333
- readonly name: string;
334
- constructor();
335
- }
336
- declare class NoStatisticsError extends Error {
337
- readonly name: string;
338
- constructor();
339
- }
340
-
341
- declare const COMMENT_REGEX: RegExp;
342
- declare const SIGN_REGEX: RegExp;
343
- declare const SIGN_REGEX_SPACE: RegExp;
344
- declare const SYMBOL_DICE = "&";
345
- declare const DETECT_CRITICAL: RegExp;
346
-
347
- /**
348
- * Definition of the Zod schema for template data
349
- */
350
-
351
- declare const templateSchema: z.ZodObject<{
352
- charName: z.ZodOptional<z.ZodBoolean>;
353
- statistics: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
354
- max: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
355
- min: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
356
- combinaison: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string | undefined, string>>>;
357
- exclude: z.ZodOptional<z.ZodBoolean>;
358
- }, z.core.$strip>>>;
359
- total: z.ZodOptional<z.ZodPipe<z.ZodNumber, z.ZodTransform<number | undefined, number>>>;
360
- forceDistrib: z.ZodOptional<z.ZodBoolean>;
361
- diceType: z.ZodOptional<z.ZodString>;
362
- critical: z.ZodOptional<z.ZodPipe<z.ZodObject<{
363
- success: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
364
- failure: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
365
- }, z.core.$strip>, z.ZodTransform<{
366
- success?: string | number | undefined;
367
- failure?: string | number | undefined;
368
- }, {
369
- success?: string | number | undefined;
370
- failure?: string | number | undefined;
371
- }>>>;
372
- customCritical: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
373
- sign: z.ZodEnum<{
374
- ">=": ">=";
375
- "<=": "<=";
376
- "<": "<";
377
- ">": ">";
378
- "!=": "!=";
379
- "==": "==";
380
- }>;
381
- value: z.ZodString;
382
- onNaturalDice: z.ZodOptional<z.ZodBoolean>;
383
- affectSkill: z.ZodOptional<z.ZodBoolean>;
384
- }, z.core.$strip>>>;
385
- damage: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
386
- }, z.core.$strip>;
387
-
388
- interface StatisticalSchema extends StatisticalTemplate {
389
- /**
390
- * Specifies the URL for the schema definition
391
- * This property is optional and should contain a valid URI.
392
- */
393
- $schema?: string;
394
- }
395
-
396
- export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, getEngine, isNumber, randomInt, replaceExpByRandom, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
411
+ export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, getEngine, getEngineId, isNumber, randomInt, replaceExpByRandom, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };