@dicelette/core 1.28.4 → 1.29.0

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,6 +1,33 @@
1
1
  import { Engine, Random } from 'random-js';
2
2
  import { z } from 'zod';
3
3
 
4
+ type FormulaValidationResult = {
5
+ ok: true;
6
+ } | {
7
+ ok: false;
8
+ error: string;
9
+ };
10
+ /**
11
+ * Validates a `customFormula` string by stripping dice-specific syntax and running
12
+ * a mathjs evaluation with a numeric test value substituted for `$`.
13
+ *
14
+ * Transformations applied before evaluation:
15
+ * - `$` → `50` (mid-range value that exercises both branches of common `>=` conditions)
16
+ * - `{cs:...}` / `{cf:...}` critical blocks → removed (they are dice-roller suffixes,
17
+ * always attached to a number — removing them leaves the number intact)
18
+ * - `{exp...}` expression blocks → removed
19
+ * - Dice notation (`1d6`, `d20`, `3d8`, …) → replaced with `3`
20
+ *
21
+ * @returns `{ ok: true }` when the formula is structurally valid mathjs,
22
+ * `{ ok: false, error }` otherwise.
23
+ *
24
+ * @example
25
+ * validateCustomFormula("$>=85?85{cs:>=5+($-85)}:$") // { ok: true }
26
+ * validateCustomFormula("$>=10?2d6:1") // { ok: true }
27
+ * validateCustomFormula("$+**2") // { ok: false, error: "..." }
28
+ */
29
+ declare function validateCustomFormula(formula: string): FormulaValidationResult;
30
+
4
31
  /**
5
32
  * Utility function that allow to get the id of an engine
6
33
  * @param engine {unknown} Engine to identify
@@ -486,4 +513,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
486
513
  */
487
514
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
488
515
 
489
- export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, type FormulaHintResult, MIN_THRESHOLD_MATCH, MaxGreater, type Modifier, NORMALIZE_SINGLE_DICE, NoStatisticsError, OPTIONAL_COMMENT, REMOVER_PATTERN, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculateSimilarity, createCriticalCustom, diceRandomParse, diceTypeRandomParse, evalCombinaison, evalOneCombinaison, evalStatsDice, findBestRecord, findBestStatMatch, generateRandomStat, generateStatsDice, getCachedRegex, getEngine, getEngineId, includeDiceType, isNumber, levenshteinDistance, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, replaceUnknown, resolveFormulaHint, roll, splitDiceComment, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyStatMatcherPattern, verifyTemplateValue };
516
+ export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, type FormulaHintResult, type FormulaValidationResult, MIN_THRESHOLD_MATCH, MaxGreater, type Modifier, NORMALIZE_SINGLE_DICE, NoStatisticsError, OPTIONAL_COMMENT, REMOVER_PATTERN, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculateSimilarity, createCriticalCustom, diceRandomParse, diceTypeRandomParse, evalCombinaison, evalOneCombinaison, evalStatsDice, findBestRecord, findBestStatMatch, generateRandomStat, generateStatsDice, getCachedRegex, getEngine, getEngineId, includeDiceType, isNumber, levenshteinDistance, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, replaceUnknown, resolveFormulaHint, roll, splitDiceComment, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, validateCustomFormula, verifyStatMatcherPattern, verifyTemplateValue };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,33 @@
1
1
  import { Engine, Random } from 'random-js';
2
2
  import { z } from 'zod';
3
3
 
4
+ type FormulaValidationResult = {
5
+ ok: true;
6
+ } | {
7
+ ok: false;
8
+ error: string;
9
+ };
10
+ /**
11
+ * Validates a `customFormula` string by stripping dice-specific syntax and running
12
+ * a mathjs evaluation with a numeric test value substituted for `$`.
13
+ *
14
+ * Transformations applied before evaluation:
15
+ * - `$` → `50` (mid-range value that exercises both branches of common `>=` conditions)
16
+ * - `{cs:...}` / `{cf:...}` critical blocks → removed (they are dice-roller suffixes,
17
+ * always attached to a number — removing them leaves the number intact)
18
+ * - `{exp...}` expression blocks → removed
19
+ * - Dice notation (`1d6`, `d20`, `3d8`, …) → replaced with `3`
20
+ *
21
+ * @returns `{ ok: true }` when the formula is structurally valid mathjs,
22
+ * `{ ok: false, error }` otherwise.
23
+ *
24
+ * @example
25
+ * validateCustomFormula("$>=85?85{cs:>=5+($-85)}:$") // { ok: true }
26
+ * validateCustomFormula("$>=10?2d6:1") // { ok: true }
27
+ * validateCustomFormula("$+**2") // { ok: false, error: "..." }
28
+ */
29
+ declare function validateCustomFormula(formula: string): FormulaValidationResult;
30
+
4
31
  /**
5
32
  * Utility function that allow to get the id of an engine
6
33
  * @param engine {unknown} Engine to identify
@@ -486,4 +513,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
486
513
  */
487
514
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
488
515
 
489
- export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, type FormulaHintResult, MIN_THRESHOLD_MATCH, MaxGreater, type Modifier, NORMALIZE_SINGLE_DICE, NoStatisticsError, OPTIONAL_COMMENT, REMOVER_PATTERN, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculateSimilarity, createCriticalCustom, diceRandomParse, diceTypeRandomParse, evalCombinaison, evalOneCombinaison, evalStatsDice, findBestRecord, findBestStatMatch, generateRandomStat, generateStatsDice, getCachedRegex, getEngine, getEngineId, includeDiceType, isNumber, levenshteinDistance, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, replaceUnknown, resolveFormulaHint, roll, splitDiceComment, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyStatMatcherPattern, verifyTemplateValue };
516
+ export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, type FormulaHintResult, type FormulaValidationResult, MIN_THRESHOLD_MATCH, MaxGreater, type Modifier, NORMALIZE_SINGLE_DICE, NoStatisticsError, OPTIONAL_COMMENT, REMOVER_PATTERN, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculateSimilarity, createCriticalCustom, diceRandomParse, diceTypeRandomParse, evalCombinaison, evalOneCombinaison, evalStatsDice, findBestRecord, findBestStatMatch, generateRandomStat, generateStatsDice, getCachedRegex, getEngine, getEngineId, includeDiceType, isNumber, levenshteinDistance, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, replaceUnknown, resolveFormulaHint, roll, splitDiceComment, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, validateCustomFormula, verifyStatMatcherPattern, verifyTemplateValue };
package/dist/index.js CHANGED
@@ -66,11 +66,81 @@ __export(index_exports, {
66
66
  templateSchema: () => templateSchema,
67
67
  testDiceRegistered: () => testDiceRegistered,
68
68
  testStatCombinaison: () => testStatCombinaison,
69
+ validateCustomFormula: () => validateCustomFormula,
69
70
  verifyStatMatcherPattern: () => verifyStatMatcherPattern,
70
71
  verifyTemplateValue: () => verifyTemplateValue
71
72
  });
72
73
  module.exports = __toCommonJS(index_exports);
73
74
 
75
+ // src/custom_formula.ts
76
+ var import_mathjs = require("mathjs");
77
+
78
+ // src/interfaces/constant.ts
79
+ var COMMENT_REGEX = /\s+(#|\/{2}|\[|\/\*)(?<comment>.*)/gi;
80
+ var SIGN_REGEX = /==|!=|(?<![!<>])>=|(?<![!<>])<=|(?<!!)(?<![<>])>|(?<!!)(?<![<>])<|(?<!!)(?<![<>])=/;
81
+ var SIGN_REGEX_SPACE = /(==|!=|(?<![!<>])>=|(?<![!<>])<=|(?<!!)(?<![<>])>|(?<!!)(?<![<>])<|(?<!!)(?<![<>])=)(\S+)/;
82
+ var SYMBOL_DICE = "&";
83
+ var DETECT_CRITICAL = /\{\*?c[fs]:([<>=]|!=)+(.+?)}/gim;
84
+ var OPTIONAL_COMMENT = /\s+(#|\/{2}|\[|\/\*)?(?<comment>.*)/gi;
85
+ var MIN_THRESHOLD_MATCH = 0.5;
86
+
87
+ // src/regex.ts
88
+ var REGEX_CACHE_MAX = 500;
89
+ var regexCache = /* @__PURE__ */ new Map();
90
+ var NORMALIZE_SINGLE_DICE = (str) => str.replace(/\b1d(\d+)/gi, "d$1");
91
+ var REMOVER_PATTERN = {
92
+ ASTERISK_ESCAPE: /\*/g,
93
+ CRITICAL_BLOCK: /\{\*?c[fs]:([<>=]|!=)+.+?\}/gim,
94
+ EXP_REMOVER: /\{exp(.*?)\}/g,
95
+ SIGN_REMOVER: /([><=]|!=)+.*$/,
96
+ STAT_COMMENTS_REMOVER: /%%.*%%/,
97
+ STAT_MATCHER: /\(?\$([\p{L}\p{M}_.][\p{L}\p{M}0-9_.]*)\)?/giu
98
+ };
99
+ function getCachedRegex(pattern, flags = "") {
100
+ const key = `${pattern}|${flags}`;
101
+ let regex = regexCache.get(key);
102
+ if (!regex) {
103
+ if (regexCache.size >= REGEX_CACHE_MAX) {
104
+ const oldest = regexCache.keys().next().value;
105
+ if (oldest !== void 0) regexCache.delete(oldest);
106
+ }
107
+ regex = new RegExp(pattern, flags);
108
+ regexCache.set(key, regex);
109
+ }
110
+ return regex;
111
+ }
112
+ function includeDiceType(dice, diceType, userStats) {
113
+ if (!diceType) return false;
114
+ diceType = NORMALIZE_SINGLE_DICE(diceType);
115
+ dice = NORMALIZE_SINGLE_DICE(dice);
116
+ if (userStats && diceType.includes("$")) {
117
+ diceType = diceType.replace("$", ".+?");
118
+ }
119
+ if (SIGN_REGEX.test(diceType)) {
120
+ diceType = diceType.replace(REMOVER_PATTERN.SIGN_REMOVER, "").trim();
121
+ dice = dice.replace(REMOVER_PATTERN.SIGN_REMOVER, "").trim();
122
+ }
123
+ if (diceType.includes("{exp")) {
124
+ diceType = diceType.replace(REMOVER_PATTERN.EXP_REMOVER, "").trim();
125
+ dice = dice.replace(REMOVER_PATTERN.EXP_REMOVER, "").trim();
126
+ }
127
+ const detectDiceType = getCachedRegex(`\\b${diceType}\\b`, "i");
128
+ return detectDiceType.test(dice);
129
+ }
130
+
131
+ // src/custom_formula.ts
132
+ var DICE_NOTATION = /\b\d*d\d+\b/gi;
133
+ function validateCustomFormula(formula) {
134
+ const expr = formula.replaceAll("$", "50").replace(REMOVER_PATTERN.CRITICAL_BLOCK, "").replace(REMOVER_PATTERN.EXP_REMOVER, "").replace(DICE_NOTATION, "3").trim();
135
+ if (!expr) return { ok: false, error: "Empty formula" };
136
+ try {
137
+ (0, import_mathjs.evaluate)(expr);
138
+ return { ok: true };
139
+ } catch (e) {
140
+ return { ok: false, error: e instanceof Error ? e.message : String(e) };
141
+ }
142
+ }
143
+
74
144
  // src/engine.ts
75
145
  var import_rpg_dice_roller = require("@dice-roller/rpg-dice-roller");
76
146
  function getEngineId(engine) {
@@ -165,15 +235,6 @@ var NoStatisticsError = class extends Error {
165
235
  }
166
236
  };
167
237
 
168
- // src/interfaces/constant.ts
169
- var COMMENT_REGEX = /\s+(#|\/{2}|\[|\/\*)(?<comment>.*)/gi;
170
- var SIGN_REGEX = /==|!=|(?<![!<>])>=|(?<![!<>])<=|(?<!!)(?<![<>])>|(?<!!)(?<![<>])<|(?<!!)(?<![<>])=/;
171
- var SIGN_REGEX_SPACE = /(==|!=|(?<![!<>])>=|(?<![!<>])<=|(?<!!)(?<![<>])>|(?<!!)(?<![<>])<|(?<!!)(?<![<>])=)(\S+)/;
172
- var SYMBOL_DICE = "&";
173
- var DETECT_CRITICAL = /\{\*?c[fs]:([<>=]|!=)+(.+?)}/gim;
174
- var OPTIONAL_COMMENT = /\s+(#|\/{2}|\[|\/\*)?(?<comment>.*)/gi;
175
- var MIN_THRESHOLD_MATCH = 0.5;
176
-
177
238
  // src/interfaces/index.ts
178
239
  var SortOrder = /* @__PURE__ */ ((SortOrder2) => {
179
240
  SortOrder2["Ascending"] = "sa";
@@ -238,57 +299,13 @@ var templateSchema = import_zod.z.object({
238
299
  damage: damageSchema
239
300
  });
240
301
 
241
- // src/regex.ts
242
- var REGEX_CACHE_MAX = 500;
243
- var regexCache = /* @__PURE__ */ new Map();
244
- var NORMALIZE_SINGLE_DICE = (str) => str.replace(/\b1d(\d+)/gi, "d$1");
245
- var REMOVER_PATTERN = {
246
- ASTERISK_ESCAPE: /\*/g,
247
- CRITICAL_BLOCK: /\{\*?c[fs]:([<>=]|!=)+.+?\}/gim,
248
- EXP_REMOVER: /\{exp(.*?)\}/g,
249
- SIGN_REMOVER: /([><=]|!=)+.*$/,
250
- STAT_COMMENTS_REMOVER: /%%.*%%/,
251
- STAT_MATCHER: /\(?\$([\p{L}\p{M}_.][\p{L}\p{M}0-9_.]*)\)?/giu
252
- };
253
- function getCachedRegex(pattern, flags = "") {
254
- const key = `${pattern}|${flags}`;
255
- let regex = regexCache.get(key);
256
- if (!regex) {
257
- if (regexCache.size >= REGEX_CACHE_MAX) {
258
- const oldest = regexCache.keys().next().value;
259
- if (oldest !== void 0) regexCache.delete(oldest);
260
- }
261
- regex = new RegExp(pattern, flags);
262
- regexCache.set(key, regex);
263
- }
264
- return regex;
265
- }
266
- function includeDiceType(dice, diceType, userStats) {
267
- if (!diceType) return false;
268
- diceType = NORMALIZE_SINGLE_DICE(diceType);
269
- dice = NORMALIZE_SINGLE_DICE(dice);
270
- if (userStats && diceType.includes("$")) {
271
- diceType = diceType.replace("$", ".+?");
272
- }
273
- if (SIGN_REGEX.test(diceType)) {
274
- diceType = diceType.replace(REMOVER_PATTERN.SIGN_REMOVER, "").trim();
275
- dice = dice.replace(REMOVER_PATTERN.SIGN_REMOVER, "").trim();
276
- }
277
- if (diceType.includes("{exp")) {
278
- diceType = diceType.replace(REMOVER_PATTERN.EXP_REMOVER, "").trim();
279
- dice = dice.replace(REMOVER_PATTERN.EXP_REMOVER, "").trim();
280
- }
281
- const detectDiceType = getCachedRegex(`\\b${diceType}\\b`, "i");
282
- return detectDiceType.test(dice);
283
- }
284
-
285
302
  // src/roll.ts
286
303
  var import_rpg_dice_roller8 = require("@dice-roller/rpg-dice-roller");
287
- var import_mathjs10 = require("mathjs");
304
+ var import_mathjs11 = require("mathjs");
288
305
 
289
306
  // src/dice/bulk.ts
290
307
  var import_rpg_dice_roller7 = require("@dice-roller/rpg-dice-roller");
291
- var import_mathjs8 = require("mathjs");
308
+ var import_mathjs9 = require("mathjs");
292
309
 
293
310
  // src/utils.ts
294
311
  var import_uniformize2 = require("uniformize");
@@ -296,7 +313,7 @@ var import_rpg_dice_roller3 = require("@dice-roller/rpg-dice-roller");
296
313
  var import_random_js2 = require("random-js");
297
314
 
298
315
  // src/verify_template.ts
299
- var import_mathjs = require("mathjs");
316
+ var import_mathjs2 = require("mathjs");
300
317
  var import_random_js = require("random-js");
301
318
  var import_uniformize = require("uniformize");
302
319
  var import_rpg_dice_roller2 = require("@dice-roller/rpg-dice-roller");
@@ -364,7 +381,7 @@ function evalCombinaison(combinaison, stats) {
364
381
  formula = formula.replace(regex, value.toString());
365
382
  }
366
383
  try {
367
- newStats[stat] = (0, import_mathjs.evaluate)(formula);
384
+ newStats[stat] = (0, import_mathjs2.evaluate)(formula);
368
385
  } catch (error) {
369
386
  throw new FormulaError(stat, "evalCombinaison", error);
370
387
  }
@@ -378,7 +395,7 @@ function evalOneCombinaison(combinaison, stats) {
378
395
  formula = formula.replace(regex, value.toString());
379
396
  }
380
397
  try {
381
- return (0, import_mathjs.evaluate)(formula);
398
+ return (0, import_mathjs2.evaluate)(formula);
382
399
  } catch (error) {
383
400
  throw new FormulaError(combinaison, "evalOneCombinaison", error);
384
401
  }
@@ -483,7 +500,7 @@ function testStatCombinaison(template, engine = import_rpg_dice_roller2.NumberGe
483
500
  formula = formula.replace(regex, randomStatValue.toString());
484
501
  }
485
502
  try {
486
- (0, import_mathjs.evaluate)(formula);
503
+ (0, import_mathjs2.evaluate)(formula);
487
504
  } catch (e) {
488
505
  error.push(stat);
489
506
  }
@@ -541,7 +558,7 @@ function createCriticalCustom(dice, customCritical, template, engine = import_rp
541
558
 
542
559
  // src/dice/compare.ts
543
560
  var import_rpg_dice_roller4 = require("@dice-roller/rpg-dice-roller");
544
- var import_mathjs2 = require("mathjs");
561
+ var import_mathjs3 = require("mathjs");
545
562
  function isTrivialComparison(maxValue, minValue, compare) {
546
563
  const canSucceed = canComparisonSucceed(maxValue, compare, minValue);
547
564
  const canFail = canComparisonFail(maxValue, compare, minValue);
@@ -580,7 +597,7 @@ function rollCompare(value, engine = import_rpg_dice_roller4.NumberGenerator.eng
580
597
  const rollComp = roll(value, engine, pity);
581
598
  if (!rollComp?.total) {
582
599
  try {
583
- return { value: (0, import_mathjs2.evaluate)(value), diceResult: value };
600
+ return { value: (0, import_mathjs3.evaluate)(value), diceResult: value };
584
601
  } catch (error) {
585
602
  return { value: 0, diceResult: value };
586
603
  }
@@ -602,7 +619,7 @@ function getCompare(dice, compareRegex, engine = import_rpg_dice_roller4.NumberG
602
619
  if (sign) {
603
620
  const toCalc = calc.replace(SIGN_REGEX, "").replace(/\s/g, "").replace(/;(.*)/, "");
604
621
  const rCompare = rollCompare(toCalc, engine, pity);
605
- const total = (0, import_mathjs2.evaluate)(rCompare.value.toString());
622
+ const total = (0, import_mathjs3.evaluate)(rCompare.value.toString());
606
623
  dice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);
607
624
  compare = {
608
625
  sign: compareSign,
@@ -644,11 +661,11 @@ function canComparisonSucceed(maxRollValue, compare, minRollValue) {
644
661
  }
645
662
 
646
663
  // src/dice/exploding.ts
647
- var import_mathjs4 = require("mathjs");
664
+ var import_mathjs5 = require("mathjs");
648
665
 
649
666
  // src/dice/signs.ts
650
667
  var import_rpg_dice_roller5 = require("@dice-roller/rpg-dice-roller");
651
- var import_mathjs3 = require("mathjs");
668
+ var import_mathjs4 = require("mathjs");
652
669
 
653
670
  // src/dice/replace.ts
654
671
  var PARENTHESIS_REGEX = /d\((\d+)\)/g;
@@ -741,7 +758,7 @@ function compareSignFormule(toRoll, compareRegex, element, diceResult, engine =
741
758
  const toCompare = `${compareResult.dice}${compareResult.compare?.sign}${compareResult.compare?.value}`;
742
759
  let res;
743
760
  try {
744
- res = (0, import_mathjs3.evaluate)(toCompare);
761
+ res = (0, import_mathjs4.evaluate)(toCompare);
745
762
  } catch (error) {
746
763
  res = roll(toCompare, engine, pity);
747
764
  }
@@ -753,7 +770,7 @@ function compareSignFormule(toRoll, compareRegex, element, diceResult, engine =
753
770
  } else if (res instanceof Object) {
754
771
  const diceResult2 = res;
755
772
  if (diceResult2.compare) {
756
- const toEvaluate = (0, import_mathjs3.evaluate)(
773
+ const toEvaluate = (0, import_mathjs4.evaluate)(
757
774
  `${diceResult2.total}${diceResult2.compare.sign}${diceResult2.compare.value}`
758
775
  );
759
776
  const sign = toEvaluate ? "\u2713" : "\u2715";
@@ -790,7 +807,7 @@ function normalizeExplodingSuccess(dice) {
790
807
  let parsedValue = Number.parseFloat(valueStr);
791
808
  if (Number.isNaN(parsedValue)) {
792
809
  try {
793
- parsedValue = Number.parseFloat((0, import_mathjs4.evaluate)(valueStr));
810
+ parsedValue = Number.parseFloat((0, import_mathjs5.evaluate)(valueStr));
794
811
  } catch (_error) {
795
812
  parsedValue = 0;
796
813
  }
@@ -828,7 +845,7 @@ function countExplodingSuccesses(diceRoll, sign, value) {
828
845
  var import_rpg_dice_roller6 = require("@dice-roller/rpg-dice-roller");
829
846
 
830
847
  // src/similarities/generateStatsDice.ts
831
- var import_mathjs5 = require("mathjs");
848
+ var import_mathjs6 = require("mathjs");
832
849
 
833
850
  // src/similarities/similarity.ts
834
851
  function calculateSimilarity(str1, str2) {
@@ -986,7 +1003,7 @@ function replaceFormulaInDice(dice) {
986
1003
  if (match.groups?.formula) {
987
1004
  const formulae = match.groups.formula.replaceAll("{{", "").replaceAll("}}", "");
988
1005
  try {
989
- const result = (0, import_mathjs5.evaluate)(formulae);
1006
+ const result = (0, import_mathjs6.evaluate)(formulae);
990
1007
  modifiedDice = modifiedDice.replace(match.groups.formula, result.toString());
991
1008
  } catch (error) {
992
1009
  throw new FormulaError(match.groups.formula, "replaceFormulasInDice", error);
@@ -1000,7 +1017,7 @@ function cleanedDice(dice) {
1000
1017
  }
1001
1018
 
1002
1019
  // src/similarities/resolveFormula.ts
1003
- var import_mathjs6 = require("mathjs");
1020
+ var import_mathjs7 = require("mathjs");
1004
1021
  function toFiniteNumber(value) {
1005
1022
  if (typeof value === "number" && Number.isFinite(value)) return value;
1006
1023
  return void 0;
@@ -1040,7 +1057,7 @@ function resolveFormulaHint(formula, allAttributes, similarityThreshold = MIN_TH
1040
1057
  progress = false;
1041
1058
  for (const [normName, expr2] of pending) {
1042
1059
  try {
1043
- const result = toFiniteNumber((0, import_mathjs6.evaluate)(expr2));
1060
+ const result = toFiniteNumber((0, import_mathjs7.evaluate)(expr2));
1044
1061
  if (result === void 0) continue;
1045
1062
  resolved.set(normName, result);
1046
1063
  pending.delete(normName);
@@ -1058,7 +1075,7 @@ function resolveFormulaHint(formula, allAttributes, similarityThreshold = MIN_TH
1058
1075
  const normFormula = trimmed.standardize();
1059
1076
  const expr = substituteFormulaTokens(normFormula, resolved, similarityThreshold);
1060
1077
  try {
1061
- const result = toFiniteNumber((0, import_mathjs6.evaluate)(expr));
1078
+ const result = toFiniteNumber((0, import_mathjs7.evaluate)(expr));
1062
1079
  if (result !== void 0) return { kind: "resolved", value: result };
1063
1080
  return { kind: "error" };
1064
1081
  } catch {
@@ -1067,10 +1084,10 @@ function resolveFormulaHint(formula, allAttributes, similarityThreshold = MIN_TH
1067
1084
  }
1068
1085
 
1069
1086
  // src/dice/calculator.ts
1070
- var import_mathjs7 = require("mathjs");
1087
+ var import_mathjs8 = require("mathjs");
1071
1088
  function calculator(sign, value, total) {
1072
1089
  if (sign === "^") sign = "**";
1073
- return (0, import_mathjs7.evaluate)(`${total} ${sign} ${value}`);
1090
+ return (0, import_mathjs8.evaluate)(`${total} ${sign} ${value}`);
1074
1091
  }
1075
1092
 
1076
1093
  // src/dice/extract.ts
@@ -1279,7 +1296,7 @@ function handleBulkRollsWithComparison(numberOfDice, diceToRoll, comments, activ
1279
1296
  results.push(formattedRollOutput);
1280
1297
  } else {
1281
1298
  const rollTotal = rollInstance.total;
1282
- const isSuccess = (0, import_mathjs8.evaluate)(
1299
+ const isSuccess = (0, import_mathjs9.evaluate)(
1283
1300
  `${rollTotal}${activeCompare.sign}${activeCompare.value}`
1284
1301
  );
1285
1302
  if (isSuccess) successCount++;
@@ -1342,7 +1359,7 @@ function handleBulkRollsWithComparison(numberOfDice, diceToRoll, comments, activ
1342
1359
  }
1343
1360
 
1344
1361
  // src/dice/pity.ts
1345
- var import_mathjs9 = require("mathjs");
1362
+ var import_mathjs10 = require("mathjs");
1346
1363
  function handlePitySystem(dice, compare, diceRoll, roller, engine) {
1347
1364
  const currentRoll = Array.isArray(diceRoll) ? diceRoll[0] : diceRoll;
1348
1365
  const maxPossible = currentRoll ? currentRoll.maxTotal : null;
@@ -1350,7 +1367,7 @@ function handlePitySystem(dice, compare, diceRoll, roller, engine) {
1350
1367
  if (!isComparisonPossible) {
1351
1368
  return { rerollCount: 0 };
1352
1369
  }
1353
- let isFail = (0, import_mathjs9.evaluate)(`${roller.total}${compare.sign}${compare.value}`);
1370
+ let isFail = (0, import_mathjs10.evaluate)(`${roller.total}${compare.sign}${compare.value}`);
1354
1371
  if (isFail) {
1355
1372
  return { rerollCount: 0 };
1356
1373
  }
@@ -1365,7 +1382,7 @@ function handlePitySystem(dice, compare, diceRoll, roller, engine) {
1365
1382
  }
1366
1383
  rerollCount++;
1367
1384
  if (res && res.total !== void 0) {
1368
- isFail = (0, import_mathjs9.evaluate)(`${res.total}${compare.sign}${compare.value}`);
1385
+ isFail = (0, import_mathjs10.evaluate)(`${res.total}${compare.sign}${compare.value}`);
1369
1386
  }
1370
1387
  }
1371
1388
  if (!res?.result.length) throw new DiceTypeError(dice, "empty_dice");
@@ -1576,7 +1593,7 @@ function sharedRolls(dice, engine = import_rpg_dice_roller8.NumberGenerator.engi
1576
1593
  const { diceAll } = replaceText(element, diceResult.total, diceResult.dice);
1577
1594
  let successCount = 0;
1578
1595
  try {
1579
- const evaluated = (0, import_mathjs10.evaluate)(toRoll);
1596
+ const evaluated = (0, import_mathjs11.evaluate)(toRoll);
1580
1597
  successCount = evaluated ? 1 : 0;
1581
1598
  } catch (error) {
1582
1599
  const evaluated = roll(toRoll, engine, pity);
@@ -1610,7 +1627,7 @@ function sharedRolls(dice, engine = import_rpg_dice_roller8.NumberGenerator.engi
1610
1627
  diceResult.dice
1611
1628
  );
1612
1629
  try {
1613
- const evaluated = (0, import_mathjs10.evaluate)(toRoll);
1630
+ const evaluated = (0, import_mathjs11.evaluate)(toRoll);
1614
1631
  results.push(`\u25C8 ${comment}${diceAll}: ${formule} = ${evaluated}`);
1615
1632
  total += Number.parseInt(evaluated, 10);
1616
1633
  } catch (error) {
@@ -1649,7 +1666,7 @@ function replaceInFormula(element, diceResult, compareResult, res, engine = impo
1649
1666
  const invertedSign = res ? compareResult.compare.sign : inverseSign(compareResult.compare.sign);
1650
1667
  let evaluateRoll;
1651
1668
  try {
1652
- evaluateRoll = (0, import_mathjs10.evaluate)(compareResult.dice);
1669
+ evaluateRoll = (0, import_mathjs11.evaluate)(compareResult.dice);
1653
1670
  return `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;
1654
1671
  } catch (error) {
1655
1672
  const evaluateRoll2 = roll(compareResult.dice, engine, pity);
@@ -1706,6 +1723,7 @@ function replaceInFormula(element, diceResult, compareResult, res, engine = impo
1706
1723
  templateSchema,
1707
1724
  testDiceRegistered,
1708
1725
  testStatCombinaison,
1726
+ validateCustomFormula,
1709
1727
  verifyStatMatcherPattern,
1710
1728
  verifyTemplateValue
1711
1729
  });