@dicelette/core 1.24.0 → 1.24.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,7 +1,56 @@
1
1
  import { Engine, Random } from 'random-js';
2
- import { DiceRoll } from '@dice-roller/rpg-dice-roller';
3
2
  import { z } from 'zod';
4
3
 
4
+ /**
5
+ * Utility function that allow to get the id of an engine
6
+ * @param engine {unknown} Engine to identify
7
+ * @returns {string} Id of the engine or "unknown"
8
+ * @private
9
+ */
10
+ declare function getEngineId(engine: unknown): string;
11
+ /**
12
+ * Utility function to get the engine from its name
13
+ * @param engine {"nativeMath" | "browserCrypto" | "nodeCrypto"} The engine name
14
+ * @returns {Engine} The engine
15
+ * @public
16
+ */
17
+ declare function getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine;
18
+
19
+ declare class DiceTypeError extends Error {
20
+ readonly dice: string;
21
+ readonly cause: string | undefined;
22
+ readonly method: unknown;
23
+ constructor(dice: string, cause?: string, method?: unknown);
24
+ }
25
+ declare class FormulaError extends Error {
26
+ readonly formula: string;
27
+ readonly cause: string | undefined;
28
+ readonly method: unknown;
29
+ constructor(formula: string, cause?: string, method?: unknown);
30
+ }
31
+ declare class MaxGreater extends Error {
32
+ readonly name: string;
33
+ readonly value: number;
34
+ readonly max: number;
35
+ constructor(value: number, max: number);
36
+ }
37
+ declare class EmptyObjectError extends Error {
38
+ readonly name: string;
39
+ constructor();
40
+ }
41
+ declare class TooManyDice extends Error {
42
+ readonly name: string;
43
+ constructor();
44
+ }
45
+ declare class TooManyStats extends Error {
46
+ readonly name: string;
47
+ constructor();
48
+ }
49
+ declare class NoStatisticsError extends Error {
50
+ readonly name: string;
51
+ constructor();
52
+ }
53
+
5
54
  interface Resultat {
6
55
  /**
7
56
  * Original dice throw
@@ -188,133 +237,6 @@ declare enum SortOrder {
188
237
  None = "none"
189
238
  }
190
239
 
191
- /**
192
- * Evaluate a formula and replace "^" by "**" if any
193
- * @param {Sign} sign
194
- * @param {number} value
195
- * @param {number} total
196
- * @returns
197
- */
198
- declare function calculator(sign: Sign, value: number, total: number): number;
199
-
200
- /**
201
- * Check if a comparison is trivial (always true or always false)
202
- * Uses the existing canComparisonSucceed logic and checks both success and failure conditions
203
- * @param maxValue Maximum possible value from the dice roll
204
- * @param minValue Minimum possible value from the dice roll
205
- * @param compare The comparison object
206
- * @returns true if the comparison is trivial (always true or always false)
207
- */
208
- declare function isTrivialComparison(maxValue: number, minValue: number, compare: ComparedValue): boolean;
209
- /**
210
- * Check if a comparison can theoretically fail given roll bounds
211
- * @param maxRollValue Maximum possible roll value
212
- * @param compare The comparison object
213
- * @param minRollValue Minimum possible roll value (defaults to 1)
214
- * @returns true if the comparison can fail at least once
215
- */
216
- declare function canComparisonFail(maxRollValue: number, compare: ComparedValue, minRollValue?: number): boolean;
217
- declare function getCompare(dice: string, compareRegex: RegExpMatchArray, engine?: Engine | null, pity?: boolean): {
218
- dice: string;
219
- compare: ComparedValue | undefined;
220
- };
221
- /**
222
- * Check if a comparison can theoretically succeed given a maximum roll value
223
- * @example
224
- * canComparisonSucceed(10, { sign: ">=", value: 15 }) => false (impossible to roll >= 15 with 1d10)
225
- * canComparisonSucceed(20, { sign: ">=", value: 15 }) => true (possible to roll >= 15 with 1d20)
226
- */
227
- declare function canComparisonSucceed(maxRollValue: number, compare: ComparedValue, minRollValue?: number): boolean;
228
-
229
- type ExplodingSuccess = {
230
- dice: string;
231
- originalDice: string;
232
- sign: Compare["sign"];
233
- value: number;
234
- normalizedSegment: string;
235
- originalSegment: string;
236
- };
237
- declare const EXPLODING_SUCCESS_REGEX: RegExp;
238
- declare function normalizeExplodingSuccess(dice: string): ExplodingSuccess | undefined;
239
- declare function countExplodingSuccesses(diceRoll: DiceRoll | DiceRoll[], sign: Compare["sign"], value: number): number;
240
-
241
- declare function getModifier(dice: string): Modifier | undefined;
242
- declare function extractValuesFromOutput(output: string): number[];
243
- declare function getRollBounds(dice: string, engine?: Engine | null): {
244
- min: number;
245
- max: number;
246
- } | undefined;
247
-
248
- declare function replaceUnwantedText(dice: string): string;
249
- declare function fixParenthesis(dice: string): string;
250
- declare function replaceText(element: string, total: number, dice: string): {
251
- formule: string;
252
- diceAll: string;
253
- };
254
- declare function formatComment(dice: string): string;
255
-
256
- declare function matchComparison(sign: Compare["sign"], val: number, value: number): boolean;
257
- declare function inverseSign(sign: "<" | ">" | ">=" | "<=" | "=" | "!=" | "=="): "<" | ">" | ">=" | "<=" | "=" | "!=" | "==";
258
- declare function compareSignFormule(toRoll: string, compareRegex: RegExpMatchArray, element: string, diceResult: Resultat, engine?: Engine | null, pity?: boolean, rollBounds?: {
259
- min: number;
260
- max: number;
261
- }): {
262
- dice: string;
263
- results: string;
264
- compare?: Compare;
265
- trivial: boolean;
266
- };
267
-
268
- /**
269
- * Utility function that allow to get the id of an engine
270
- * @param engine {unknown} Engine to identify
271
- * @returns {string} Id of the engine or "unknown"
272
- * @private
273
- */
274
- declare function getEngineId(engine: unknown): string;
275
- /**
276
- * Utility function to get the engine from its name
277
- * @param engine {"nativeMath" | "browserCrypto" | "nodeCrypto"} The engine name
278
- * @returns {Engine} The engine
279
- * @public
280
- */
281
- declare function getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine;
282
-
283
- declare class DiceTypeError extends Error {
284
- readonly dice: string;
285
- readonly cause: string | undefined;
286
- readonly method: unknown;
287
- constructor(dice: string, cause?: string, method?: unknown);
288
- }
289
- declare class FormulaError extends Error {
290
- readonly formula: string;
291
- readonly cause: string | undefined;
292
- readonly method: unknown;
293
- constructor(formula: string, cause?: string, method?: unknown);
294
- }
295
- declare class MaxGreater extends Error {
296
- readonly name: string;
297
- readonly value: number;
298
- readonly max: number;
299
- constructor(value: number, max: number);
300
- }
301
- declare class EmptyObjectError extends Error {
302
- readonly name: string;
303
- constructor();
304
- }
305
- declare class TooManyDice extends Error {
306
- readonly name: string;
307
- constructor();
308
- }
309
- declare class TooManyStats extends Error {
310
- readonly name: string;
311
- constructor();
312
- }
313
- declare class NoStatisticsError extends Error {
314
- readonly name: string;
315
- constructor();
316
- }
317
-
318
240
  declare const COMMENT_REGEX: RegExp;
319
241
  declare const SIGN_REGEX: RegExp;
320
242
  declare const SIGN_REGEX_SPACE: RegExp;
@@ -384,19 +306,6 @@ declare function replaceInFormula(element: string, diceResult: Resultat, compare
384
306
  dice: string;
385
307
  compare: Compare | undefined;
386
308
  }, res: boolean, engine?: Engine | null, pity?: boolean): string;
387
- declare function rollCompare(value: unknown, engine?: Engine | null, pity?: boolean): {
388
- value: number;
389
- diceResult?: undefined;
390
- dice?: undefined;
391
- } | {
392
- value: any;
393
- diceResult: string;
394
- dice?: undefined;
395
- } | {
396
- dice: string;
397
- value: number;
398
- diceResult: string;
399
- };
400
309
 
401
310
  /**
402
311
  * Escape regex string
@@ -521,4 +430,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
521
430
  */
522
431
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
523
432
 
524
- export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EXPLODING_SUCCESS_REGEX, EmptyObjectError, type ExplodingSuccess, FormulaError, MaxGreater, type Modifier, NoStatisticsError, OPTIONAL_COMMENT, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, canComparisonFail, canComparisonSucceed, compareSignFormule, countExplodingSuccesses, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, extractValuesFromOutput, fixParenthesis, formatComment, generateRandomStat, generateStatsDice, getCompare, getEngine, getEngineId, getModifier, getRollBounds, inverseSign, isNumber, isTrivialComparison, matchComparison, normalizeExplodingSuccess, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, replaceText, replaceUnwantedText, roll, rollCompare, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
433
+ export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, OPTIONAL_COMMENT, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, getEngine, getEngineId, isNumber, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,56 @@
1
1
  import { Engine, Random } from 'random-js';
2
- import { DiceRoll } from '@dice-roller/rpg-dice-roller';
3
2
  import { z } from 'zod';
4
3
 
4
+ /**
5
+ * Utility function that allow to get the id of an engine
6
+ * @param engine {unknown} Engine to identify
7
+ * @returns {string} Id of the engine or "unknown"
8
+ * @private
9
+ */
10
+ declare function getEngineId(engine: unknown): string;
11
+ /**
12
+ * Utility function to get the engine from its name
13
+ * @param engine {"nativeMath" | "browserCrypto" | "nodeCrypto"} The engine name
14
+ * @returns {Engine} The engine
15
+ * @public
16
+ */
17
+ declare function getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine;
18
+
19
+ declare class DiceTypeError extends Error {
20
+ readonly dice: string;
21
+ readonly cause: string | undefined;
22
+ readonly method: unknown;
23
+ constructor(dice: string, cause?: string, method?: unknown);
24
+ }
25
+ declare class FormulaError extends Error {
26
+ readonly formula: string;
27
+ readonly cause: string | undefined;
28
+ readonly method: unknown;
29
+ constructor(formula: string, cause?: string, method?: unknown);
30
+ }
31
+ declare class MaxGreater extends Error {
32
+ readonly name: string;
33
+ readonly value: number;
34
+ readonly max: number;
35
+ constructor(value: number, max: number);
36
+ }
37
+ declare class EmptyObjectError extends Error {
38
+ readonly name: string;
39
+ constructor();
40
+ }
41
+ declare class TooManyDice extends Error {
42
+ readonly name: string;
43
+ constructor();
44
+ }
45
+ declare class TooManyStats extends Error {
46
+ readonly name: string;
47
+ constructor();
48
+ }
49
+ declare class NoStatisticsError extends Error {
50
+ readonly name: string;
51
+ constructor();
52
+ }
53
+
5
54
  interface Resultat {
6
55
  /**
7
56
  * Original dice throw
@@ -188,133 +237,6 @@ declare enum SortOrder {
188
237
  None = "none"
189
238
  }
190
239
 
191
- /**
192
- * Evaluate a formula and replace "^" by "**" if any
193
- * @param {Sign} sign
194
- * @param {number} value
195
- * @param {number} total
196
- * @returns
197
- */
198
- declare function calculator(sign: Sign, value: number, total: number): number;
199
-
200
- /**
201
- * Check if a comparison is trivial (always true or always false)
202
- * Uses the existing canComparisonSucceed logic and checks both success and failure conditions
203
- * @param maxValue Maximum possible value from the dice roll
204
- * @param minValue Minimum possible value from the dice roll
205
- * @param compare The comparison object
206
- * @returns true if the comparison is trivial (always true or always false)
207
- */
208
- declare function isTrivialComparison(maxValue: number, minValue: number, compare: ComparedValue): boolean;
209
- /**
210
- * Check if a comparison can theoretically fail given roll bounds
211
- * @param maxRollValue Maximum possible roll value
212
- * @param compare The comparison object
213
- * @param minRollValue Minimum possible roll value (defaults to 1)
214
- * @returns true if the comparison can fail at least once
215
- */
216
- declare function canComparisonFail(maxRollValue: number, compare: ComparedValue, minRollValue?: number): boolean;
217
- declare function getCompare(dice: string, compareRegex: RegExpMatchArray, engine?: Engine | null, pity?: boolean): {
218
- dice: string;
219
- compare: ComparedValue | undefined;
220
- };
221
- /**
222
- * Check if a comparison can theoretically succeed given a maximum roll value
223
- * @example
224
- * canComparisonSucceed(10, { sign: ">=", value: 15 }) => false (impossible to roll >= 15 with 1d10)
225
- * canComparisonSucceed(20, { sign: ">=", value: 15 }) => true (possible to roll >= 15 with 1d20)
226
- */
227
- declare function canComparisonSucceed(maxRollValue: number, compare: ComparedValue, minRollValue?: number): boolean;
228
-
229
- type ExplodingSuccess = {
230
- dice: string;
231
- originalDice: string;
232
- sign: Compare["sign"];
233
- value: number;
234
- normalizedSegment: string;
235
- originalSegment: string;
236
- };
237
- declare const EXPLODING_SUCCESS_REGEX: RegExp;
238
- declare function normalizeExplodingSuccess(dice: string): ExplodingSuccess | undefined;
239
- declare function countExplodingSuccesses(diceRoll: DiceRoll | DiceRoll[], sign: Compare["sign"], value: number): number;
240
-
241
- declare function getModifier(dice: string): Modifier | undefined;
242
- declare function extractValuesFromOutput(output: string): number[];
243
- declare function getRollBounds(dice: string, engine?: Engine | null): {
244
- min: number;
245
- max: number;
246
- } | undefined;
247
-
248
- declare function replaceUnwantedText(dice: string): string;
249
- declare function fixParenthesis(dice: string): string;
250
- declare function replaceText(element: string, total: number, dice: string): {
251
- formule: string;
252
- diceAll: string;
253
- };
254
- declare function formatComment(dice: string): string;
255
-
256
- declare function matchComparison(sign: Compare["sign"], val: number, value: number): boolean;
257
- declare function inverseSign(sign: "<" | ">" | ">=" | "<=" | "=" | "!=" | "=="): "<" | ">" | ">=" | "<=" | "=" | "!=" | "==";
258
- declare function compareSignFormule(toRoll: string, compareRegex: RegExpMatchArray, element: string, diceResult: Resultat, engine?: Engine | null, pity?: boolean, rollBounds?: {
259
- min: number;
260
- max: number;
261
- }): {
262
- dice: string;
263
- results: string;
264
- compare?: Compare;
265
- trivial: boolean;
266
- };
267
-
268
- /**
269
- * Utility function that allow to get the id of an engine
270
- * @param engine {unknown} Engine to identify
271
- * @returns {string} Id of the engine or "unknown"
272
- * @private
273
- */
274
- declare function getEngineId(engine: unknown): string;
275
- /**
276
- * Utility function to get the engine from its name
277
- * @param engine {"nativeMath" | "browserCrypto" | "nodeCrypto"} The engine name
278
- * @returns {Engine} The engine
279
- * @public
280
- */
281
- declare function getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine;
282
-
283
- declare class DiceTypeError extends Error {
284
- readonly dice: string;
285
- readonly cause: string | undefined;
286
- readonly method: unknown;
287
- constructor(dice: string, cause?: string, method?: unknown);
288
- }
289
- declare class FormulaError extends Error {
290
- readonly formula: string;
291
- readonly cause: string | undefined;
292
- readonly method: unknown;
293
- constructor(formula: string, cause?: string, method?: unknown);
294
- }
295
- declare class MaxGreater extends Error {
296
- readonly name: string;
297
- readonly value: number;
298
- readonly max: number;
299
- constructor(value: number, max: number);
300
- }
301
- declare class EmptyObjectError extends Error {
302
- readonly name: string;
303
- constructor();
304
- }
305
- declare class TooManyDice extends Error {
306
- readonly name: string;
307
- constructor();
308
- }
309
- declare class TooManyStats extends Error {
310
- readonly name: string;
311
- constructor();
312
- }
313
- declare class NoStatisticsError extends Error {
314
- readonly name: string;
315
- constructor();
316
- }
317
-
318
240
  declare const COMMENT_REGEX: RegExp;
319
241
  declare const SIGN_REGEX: RegExp;
320
242
  declare const SIGN_REGEX_SPACE: RegExp;
@@ -384,19 +306,6 @@ declare function replaceInFormula(element: string, diceResult: Resultat, compare
384
306
  dice: string;
385
307
  compare: Compare | undefined;
386
308
  }, res: boolean, engine?: Engine | null, pity?: boolean): string;
387
- declare function rollCompare(value: unknown, engine?: Engine | null, pity?: boolean): {
388
- value: number;
389
- diceResult?: undefined;
390
- dice?: undefined;
391
- } | {
392
- value: any;
393
- diceResult: string;
394
- dice?: undefined;
395
- } | {
396
- dice: string;
397
- value: number;
398
- diceResult: string;
399
- };
400
309
 
401
310
  /**
402
311
  * Escape regex string
@@ -521,4 +430,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
521
430
  */
522
431
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
523
432
 
524
- export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EXPLODING_SUCCESS_REGEX, EmptyObjectError, type ExplodingSuccess, FormulaError, MaxGreater, type Modifier, NoStatisticsError, OPTIONAL_COMMENT, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, canComparisonFail, canComparisonSucceed, compareSignFormule, countExplodingSuccesses, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, extractValuesFromOutput, fixParenthesis, formatComment, generateRandomStat, generateStatsDice, getCompare, getEngine, getEngineId, getModifier, getRollBounds, inverseSign, isNumber, isTrivialComparison, matchComparison, normalizeExplodingSuccess, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, replaceText, replaceUnwantedText, roll, rollCompare, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
433
+ export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, OPTIONAL_COMMENT, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, getEngine, getEngineId, isNumber, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };