@dicelette/core 1.4.2 → 1.4.4

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,4 +1,3 @@
1
- declare const COMMENT_REGEX: RegExp;
2
1
  /**
3
2
  * Parse the string provided and turn it as a readable dice for dice parser
4
3
  * @param dice {string}
@@ -12,7 +11,6 @@ declare function roll(dice: string): Resultat | undefined;
12
11
  * @returns
13
12
  */
14
13
  declare function calculator(sign: Sign, value: number, total: number): number;
15
- declare function multipleFunction(dice: string): Resultat | undefined;
16
14
 
17
15
  interface Resultat {
18
16
  /**
@@ -257,4 +255,9 @@ declare class NoStatisticsError extends Error {
257
255
  constructor();
258
256
  }
259
257
 
260
- 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, multipleFunction, replaceFormulaInDice, roll, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
258
+ declare const COMMENT_REGEX: RegExp;
259
+ declare const SIGN_REGEX: RegExp;
260
+ declare const SIGN_REGEX_SPACE: RegExp;
261
+ declare const SYMBOL_DICE = "&";
262
+
263
+ export { COMMENT_REGEX, type Compare, type Critical, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, 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,4 +1,3 @@
1
- declare const COMMENT_REGEX: RegExp;
2
1
  /**
3
2
  * Parse the string provided and turn it as a readable dice for dice parser
4
3
  * @param dice {string}
@@ -12,7 +11,6 @@ declare function roll(dice: string): Resultat | undefined;
12
11
  * @returns
13
12
  */
14
13
  declare function calculator(sign: Sign, value: number, total: number): number;
15
- declare function multipleFunction(dice: string): Resultat | undefined;
16
14
 
17
15
  interface Resultat {
18
16
  /**
@@ -257,4 +255,9 @@ declare class NoStatisticsError extends Error {
257
255
  constructor();
258
256
  }
259
257
 
260
- 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, multipleFunction, replaceFormulaInDice, roll, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
258
+ declare const COMMENT_REGEX: RegExp;
259
+ declare const SIGN_REGEX: RegExp;
260
+ declare const SIGN_REGEX_SPACE: RegExp;
261
+ declare const SYMBOL_DICE = "&";
262
+
263
+ export { COMMENT_REGEX, type Compare, type Critical, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, 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.js CHANGED
@@ -36,6 +36,9 @@ __export(src_exports, {
36
36
  FormulaError: () => FormulaError,
37
37
  MaxGreater: () => MaxGreater,
38
38
  NoStatisticsError: () => NoStatisticsError,
39
+ SIGN_REGEX: () => SIGN_REGEX,
40
+ SIGN_REGEX_SPACE: () => SIGN_REGEX_SPACE,
41
+ SYMBOL_DICE: () => SYMBOL_DICE,
39
42
  TooManyDice: () => TooManyDice,
40
43
  TooManyStats: () => TooManyStats,
41
44
  calculator: () => calculator,
@@ -48,7 +51,6 @@ __export(src_exports, {
48
51
  evalStatsDice: () => evalStatsDice,
49
52
  generateRandomStat: () => generateRandomStat,
50
53
  generateStatsDice: () => generateStatsDice,
51
- multipleFunction: () => multipleFunction,
52
54
  replaceFormulaInDice: () => replaceFormulaInDice,
53
55
  roll: () => roll,
54
56
  testDiceRegistered: () => testDiceRegistered,
@@ -126,15 +128,18 @@ var NoStatisticsError = class extends Error {
126
128
  }
127
129
  };
128
130
 
129
- // src/dice.ts
131
+ // src/interfaces/constant.ts
130
132
  var COMMENT_REGEX = /\s+(#|\/{2}|\[|\/\*)(.*)/;
131
133
  var SIGN_REGEX = /[><=!]+/;
132
134
  var SIGN_REGEX_SPACE = /[><=!]+(\S+)/;
135
+ var SYMBOL_DICE = "&";
136
+
137
+ // src/dice.ts
133
138
  function getCompare(dice, compareRegex) {
134
139
  dice = dice.replace(SIGN_REGEX_SPACE, "");
135
140
  let compare;
136
141
  const calc = compareRegex[1];
137
- const sign = calc.match(/[+-\/\*\^]/)?.[0];
142
+ const sign = calc.match(/[+-\/*^]/)?.[0];
138
143
  const compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];
139
144
  if (sign) {
140
145
  const toCalc = calc.replace(SIGN_REGEX, "").replace(/\s/g, "").replace(/;(.*)/, "");
@@ -152,7 +157,7 @@ function getCompare(dice, compareRegex) {
152
157
  return { dice, compare };
153
158
  }
154
159
  function getModifier(dice) {
155
- const modifier = dice.matchAll(/(\+|\-|%|\/|\^|\*|\*{2})(\d+)/gi);
160
+ const modifier = dice.matchAll(/(\+|-|%|\/|\^|\*|\*{2})(\d+)/gi);
156
161
  let modificator;
157
162
  for (const mod of modifier) {
158
163
  if (modificator) {
@@ -178,8 +183,8 @@ function roll(dice) {
178
183
  return void 0;
179
184
  const compareRegex = dice.match(SIGN_REGEX_SPACE);
180
185
  let compare;
181
- if (dice.includes(";") && dice.includes("\xB5"))
182
- return multipleFunction(dice);
186
+ if (dice.includes(";") && dice.includes("&"))
187
+ return sharedRolls(dice);
183
188
  if (compareRegex) {
184
189
  const compareResult = getCompare(dice, compareRegex);
185
190
  dice = compareResult.dice;
@@ -251,8 +256,11 @@ function inverseSign(sign) {
251
256
  }
252
257
  }
253
258
  function replaceInFormula(element, diceResult, compareResult, res) {
254
- const formule = element.replace("\xB5", `[${diceResult.total}]`);
255
- const diceAll = element.replace("\xB5", `[${diceResult.dice.replace(COMMENT_REGEX, "")}]`);
259
+ const { formule, diceAll } = replaceText(
260
+ element,
261
+ diceResult.total ?? 0,
262
+ diceResult.dice
263
+ );
256
264
  const validSign = res ? "\u2713" : "\u2715";
257
265
  const invertedSign = res ? compareResult.compare.sign : inverseSign(compareResult.compare.sign);
258
266
  let evaluateRoll;
@@ -279,20 +287,32 @@ function compareSignFormule(toRoll, compareRegex, element, diceResult) {
279
287
  if (typeof res === "boolean") {
280
288
  results = replaceInFormula(element, diceResult, compareResult, res);
281
289
  } else if (res instanceof Object) {
282
- const result = res;
283
- if (result.compare) {
290
+ const diceResult2 = res;
291
+ if (diceResult2.compare) {
284
292
  const toEvaluate = (0, import_mathjs.evaluate)(
285
- `${result.total}${result.compare.sign}${result.compare.value}`
293
+ `${diceResult2.total}${diceResult2.compare.sign}${diceResult2.compare.value}`
286
294
  );
287
295
  const sign = toEvaluate ? "\u2713" : "\u2715";
288
- const invertedSign = toEvaluate ? result.compare.sign : inverseSign(result.compare.sign);
289
- const dice = element.replace("\xB5", `[${diceResult.dice.replace(COMMENT_REGEX, "")}]`).trim();
290
- results = `${sign} ${dice}: ${result.result.split(":").splice(1).join(":").trim()}${invertedSign}${result.compare.value}`;
296
+ const invertedSign = toEvaluate ? diceResult2.compare.sign : inverseSign(diceResult2.compare.sign);
297
+ const dice = replaceText(element, 0, diceResult2.dice).diceAll;
298
+ results = `${sign} ${dice}: ${diceResult2.result.split(":").splice(1).join(":").trim()}${invertedSign}${diceResult2.compare.value}`;
291
299
  }
292
300
  }
293
301
  return { dice: compareResult.dice, results };
294
302
  }
295
- function multipleFunction(dice) {
303
+ function replaceText(element, total, dice) {
304
+ return {
305
+ formule: element.replace(SYMBOL_DICE, `[${total}]`).trim(),
306
+ diceAll: element.replace(SYMBOL_DICE, `[${dice.replace(COMMENT_REGEX, "")}]`).trim()
307
+ };
308
+ }
309
+ function sharedRolls(dice) {
310
+ if (dice.includes("#"))
311
+ throw new DiceTypeError(
312
+ dice,
313
+ "noBulkRoll",
314
+ "bulk roll are not allowed in shared rolls"
315
+ );
296
316
  const results = [];
297
317
  const split = dice.split(";");
298
318
  const diceResult = roll(split[0]);
@@ -304,7 +324,7 @@ function multipleFunction(dice) {
304
324
  if (!total)
305
325
  return diceResult;
306
326
  for (let element of split.slice(1)) {
307
- if (!element.includes("\xB5")) {
327
+ if (!element.includes(SYMBOL_DICE)) {
308
328
  const result = roll(element);
309
329
  if (!result)
310
330
  continue;
@@ -316,17 +336,17 @@ function multipleFunction(dice) {
316
336
  const comment = commentMatch ? commentMatch[2] : void 0;
317
337
  if (comment)
318
338
  comments += ` ${comment}`;
319
- let toRoll = element.replace("\xB5", `${diceResult.total}`);
339
+ let toRoll = element.replace(SYMBOL_DICE, `${diceResult.total}`);
320
340
  const compareRegex = toRoll.match(SIGN_REGEX_SPACE);
321
341
  if (compareRegex) {
322
342
  const compareResult = compareSignFormule(toRoll, compareRegex, element, diceResult);
323
343
  toRoll = compareResult.dice;
324
344
  results.push(compareResult.results);
325
345
  } else {
326
- const formule = element.replace("\xB5", `[${diceResult.total}]`).trim();
327
- const diceAll = element.replace(
328
- "\xB5",
329
- `[${diceResult.dice.replace(COMMENT_REGEX, "")}]`
346
+ const { formule, diceAll } = replaceText(
347
+ element,
348
+ diceResult.total,
349
+ diceResult.dice
330
350
  );
331
351
  try {
332
352
  const evaluated = (0, import_mathjs.evaluate)(toRoll);
@@ -337,7 +357,7 @@ function multipleFunction(dice) {
337
357
  if (evaluated)
338
358
  results.push(`\u25C8 ${diceAll}: ${evaluated.result.split(":").slice(1).join(":")}`);
339
359
  else
340
- results.push(`\u25C8 ${diceAll}:${formule} = ${evaluated}`);
360
+ results.push(`\u25C8 ${diceAll}: ${formule} = ${evaluated}`);
341
361
  total += evaluated?.total ?? 0;
342
362
  }
343
363
  }
@@ -393,13 +413,13 @@ function cleanedDice(dice) {
393
413
  // src/verify_template.ts
394
414
  var import_mathjs3 = require("mathjs");
395
415
  var import_random_js = require("random-js");
396
- var import_remove_accents2 = __toESM(require("remove-accents"));
416
+ var import_uniformize = require("uniformize");
397
417
  function evalStatsDice(testDice, stats) {
398
418
  let dice = testDice;
399
419
  if (stats && Object.keys(stats).length > 0) {
400
420
  const allStats = Object.keys(stats);
401
421
  for (const stat of allStats) {
402
- const regex = new RegExp(escapeRegex((0, import_remove_accents2.default)(stat)), "gi");
422
+ const regex = new RegExp(escapeRegex(stat.standardize()), "gi");
403
423
  if (testDice.match(regex)) {
404
424
  const statValue = stats[stat];
405
425
  dice = testDice.replace(regex, statValue.toString());
@@ -417,10 +437,8 @@ function evalStatsDice(testDice, stats) {
417
437
  function diceRandomParse(value, template) {
418
438
  if (!template.statistics)
419
439
  return value;
420
- value = (0, import_remove_accents2.default)(value);
421
- const allStats = Object.keys(template.statistics).map(
422
- (stat) => (0, import_remove_accents2.default)(stat).toLowerCase()
423
- );
440
+ value = value.standardize();
441
+ const allStats = Object.keys(template.statistics).map((stat) => stat.standardize());
424
442
  let newDice = value;
425
443
  for (const stat of allStats) {
426
444
  const regex = new RegExp(escapeRegex(stat), "gi");
@@ -429,8 +447,8 @@ function diceRandomParse(value, template) {
429
447
  let min = void 0;
430
448
  const stats = template.statistics?.[stat];
431
449
  if (stats) {
432
- max = template.statistics[(0, import_remove_accents2.default)(stat).toLowerCase()].max;
433
- min = template.statistics[(0, import_remove_accents2.default)(stat).toLowerCase()].min;
450
+ max = template.statistics[stat.standardize()].max;
451
+ min = template.statistics[stat.standardize()].min;
434
452
  }
435
453
  const total = template.total || 100;
436
454
  const randomStatValue = generateRandomStat(total, max, min);
@@ -442,12 +460,12 @@ function diceRandomParse(value, template) {
442
460
  function diceTypeRandomParse(dice, template) {
443
461
  if (!template.statistics)
444
462
  return dice;
445
- const firstStatNotCombinaison = Object.keys(template.statistics).find(
463
+ const firstStatNotcombinaison = Object.keys(template.statistics).find(
446
464
  (stat) => !template.statistics?.[stat].combinaison
447
465
  );
448
- if (!firstStatNotCombinaison)
466
+ if (!firstStatNotcombinaison)
449
467
  return dice;
450
- const stats = template.statistics[firstStatNotCombinaison];
468
+ const stats = template.statistics[firstStatNotcombinaison];
451
469
  const { min, max } = stats;
452
470
  const total = template.total || 100;
453
471
  const randomStatValue = generateRandomStat(total, max, min);
@@ -456,14 +474,13 @@ function diceTypeRandomParse(dice, template) {
456
474
  function evalCombinaison(combinaison, stats) {
457
475
  const newStats = {};
458
476
  for (const [stat, combin] of Object.entries(combinaison)) {
459
- let formula = (0, import_remove_accents2.default)(combin);
477
+ let formula = combin.standardize();
460
478
  for (const [statName, value] of Object.entries(stats)) {
461
- const regex = new RegExp((0, import_remove_accents2.default)(statName), "gi");
479
+ const regex = new RegExp(statName.standardize(), "gi");
462
480
  formula = formula.replace(regex, value.toString());
463
481
  }
464
482
  try {
465
- const result = (0, import_mathjs3.evaluate)(formula);
466
- newStats[stat] = result;
483
+ newStats[stat] = (0, import_mathjs3.evaluate)(formula);
467
484
  } catch (error) {
468
485
  throw new FormulaError(stat, "evalCombinaison", error);
469
486
  }
@@ -471,9 +488,9 @@ function evalCombinaison(combinaison, stats) {
471
488
  return newStats;
472
489
  }
473
490
  function evalOneCombinaison(combinaison, stats) {
474
- let formula = (0, import_remove_accents2.default)(combinaison);
491
+ let formula = combinaison.standardize();
475
492
  for (const [statName, value] of Object.entries(stats)) {
476
- const regex = new RegExp((0, import_remove_accents2.default)(statName), "gi");
493
+ const regex = new RegExp(statName.standardize(), "gi");
477
494
  formula = formula.replace(regex, value.toString());
478
495
  }
479
496
  try {
@@ -500,7 +517,7 @@ function verifyTemplateValue(template) {
500
517
  dataValue.max = void 0;
501
518
  if (dataValue.min && dataValue.min <= 0)
502
519
  dataValue.min = void 0;
503
- let formula = dataValue.combinaison ? (0, import_remove_accents2.default)(dataValue.combinaison).toLowerCase() : void 0;
520
+ let formula = dataValue.combinaison ? dataValue.combinaison.standardize() : void 0;
504
521
  formula = formula && formula.trim().length > 0 ? formula : void 0;
505
522
  if (!statistiqueTemplate.statistics) {
506
523
  statistiqueTemplate.statistics = {};
@@ -513,15 +530,11 @@ function verifyTemplateValue(template) {
513
530
  }
514
531
  }
515
532
  if (template.diceType) {
516
- try {
517
- statistiqueTemplate.diceType = template.diceType;
518
- const cleanedDice2 = diceTypeRandomParse(template.diceType, statistiqueTemplate);
519
- const rolled = roll(cleanedDice2);
520
- if (!rolled)
521
- throw new DiceTypeError(cleanedDice2, "verifyTemplateValue", "no roll result");
522
- } catch (e) {
523
- throw new Error(e.message);
524
- }
533
+ statistiqueTemplate.diceType = template.diceType;
534
+ const cleanedDice2 = diceTypeRandomParse(template.diceType, statistiqueTemplate);
535
+ const rolled = roll(cleanedDice2);
536
+ if (!rolled)
537
+ throw new DiceTypeError(cleanedDice2, "verifyTemplateValue", "no roll result");
525
538
  }
526
539
  if (template.critical && Object.keys(template.critical).length > 0) {
527
540
  statistiqueTemplate.critical = {
@@ -538,12 +551,8 @@ function verifyTemplateValue(template) {
538
551
  statistiqueTemplate.charName = template.charName;
539
552
  if (template.damage)
540
553
  statistiqueTemplate.damage = template.damage;
541
- try {
542
- testDiceRegistered(statistiqueTemplate);
543
- testStatCombinaison(statistiqueTemplate);
544
- } catch (error) {
545
- throw new Error(error.message);
546
- }
554
+ testDiceRegistered(statistiqueTemplate);
555
+ testStatCombinaison(statistiqueTemplate);
547
556
  return statistiqueTemplate;
548
557
  }
549
558
  function testDiceRegistered(template) {
@@ -569,7 +578,7 @@ function testDiceRegistered(template) {
569
578
  function testStatCombinaison(template) {
570
579
  if (!template.statistics)
571
580
  return;
572
- const onlyCombinaisonStats = Object.fromEntries(
581
+ const onlycombinaisonStats = Object.fromEntries(
573
582
  Object.entries(template.statistics).filter(
574
583
  ([_, value]) => value.combinaison !== void 0
575
584
  )
@@ -577,7 +586,7 @@ function testStatCombinaison(template) {
577
586
  const allOtherStats = Object.fromEntries(
578
587
  Object.entries(template.statistics).filter(([_, value]) => !value.combinaison)
579
588
  );
580
- if (Object.keys(onlyCombinaisonStats).length === 0)
589
+ if (Object.keys(onlycombinaisonStats).length === 0)
581
590
  return;
582
591
  const allStats = Object.keys(template.statistics).filter(
583
592
  (stat) => !template.statistics[stat].combinaison
@@ -585,7 +594,7 @@ function testStatCombinaison(template) {
585
594
  if (allStats.length === 0)
586
595
  throw new NoStatisticsError();
587
596
  const error = [];
588
- for (const [stat, value] of Object.entries(onlyCombinaisonStats)) {
597
+ for (const [stat, value] of Object.entries(onlycombinaisonStats)) {
589
598
  let formula = value.combinaison;
590
599
  for (const [other, data] of Object.entries(allOtherStats)) {
591
600
  const { max, min } = data;
@@ -627,6 +636,9 @@ function generateRandomStat(total = 100, max, min) {
627
636
  FormulaError,
628
637
  MaxGreater,
629
638
  NoStatisticsError,
639
+ SIGN_REGEX,
640
+ SIGN_REGEX_SPACE,
641
+ SYMBOL_DICE,
630
642
  TooManyDice,
631
643
  TooManyStats,
632
644
  calculator,
@@ -639,7 +651,6 @@ function generateRandomStat(total = 100, max, min) {
639
651
  evalStatsDice,
640
652
  generateRandomStat,
641
653
  generateStatsDice,
642
- multipleFunction,
643
654
  replaceFormulaInDice,
644
655
  roll,
645
656
  testDiceRegistered,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/dice.ts","../src/errors.ts","../src/utils.ts","../src/verify_template.ts"],"sourcesContent":["export * from \"./dice\";\nexport * from \"./interface\";\nexport * from \"./utils\";\nexport * from \"./verify_template\";\nexport * from \"./errors\";\n","/* eslint-disable no-useless-escape */\nimport { DiceRoller } from \"@dice-roller/rpg-dice-roller\";\nimport { evaluate } from \"mathjs\";\n\nimport type { Compare, Modifier, Resultat, Sign } from \".\";\nimport { DiceTypeError } from \"./errors\";\n\nexport const COMMENT_REGEX = /\\s+(#|\\/{2}|\\[|\\/\\*)(.*)/;\nconst SIGN_REGEX = /[><=!]+/;\nconst SIGN_REGEX_SPACE = /[><=!]+(\\S+)/;\n\nfunction getCompare(\n\tdice: string,\n\tcompareRegex: RegExpMatchArray\n): { dice: string; compare: Compare | undefined } {\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\tdice = dice.replace(SIGN_REGEX_SPACE, \"\");\n\tlet compare: Compare;\n\tconst calc = compareRegex[1];\n\tconst sign = calc.match(/[+-\\/\\*\\^]/)?.[0];\n\tconst compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];\n\tif (sign) {\n\t\tconst toCalc = calc.replace(SIGN_REGEX, \"\").replace(/\\s/g, \"\").replace(/;(.*)/, \"\");\n\t\tconst total = evaluate(toCalc);\n\t\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\t\tdice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);\n\t\tcompare = {\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\n\t\t\tvalue: total,\n\t\t};\n\t} else\n\t\tcompare = {\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\n\t\t\tvalue: Number.parseInt(calc, 10),\n\t\t};\n\treturn { dice, compare };\n}\n\nfunction getModifier(dice: string) {\n\tconst modifier = dice.matchAll(/(\\+|\\-|%|\\/|\\^|\\*|\\*{2})(\\d+)/gi);\n\tlet modificator: Modifier | undefined;\n\tfor (const mod of modifier) {\n\t\t//calculate the modifier if multiple\n\t\tif (modificator) {\n\t\t\tconst sign = modificator.sign;\n\t\t\tlet value = modificator.value;\n\t\t\tif (sign) value = calculator(sign, value, Number.parseInt(mod[2], 10));\n\t\t\tmodificator = {\n\t\t\t\tsign: mod[1] as Sign,\n\t\t\t\tvalue,\n\t\t\t};\n\t\t} else {\n\t\t\tmodificator = {\n\t\t\t\tsign: mod[1] as Sign,\n\t\t\t\tvalue: Number.parseInt(mod[2], 10),\n\t\t\t};\n\t\t}\n\t}\n\treturn modificator;\n}\n\n/**\n * Parse the string provided and turn it as a readable dice for dice parser\n * @param dice {string}\n */\nexport function roll(dice: string): Resultat | undefined {\n\t//parse dice string\n\tif (!dice.includes(\"d\")) return undefined;\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\n\tlet compare: Compare | undefined;\n\tif (dice.includes(\";\") && dice.includes(\"µ\")) return multipleFunction(dice);\n\tif (compareRegex) {\n\t\tconst compareResult = getCompare(dice, compareRegex);\n\t\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\t\tdice = compareResult.dice;\n\t\tcompare = compareResult.compare;\n\t}\n\tconst modificator = getModifier(dice);\n\n\tif (dice.match(/\\d+?#(.*)/)) {\n\t\tconst diceArray = dice.split(\"#\");\n\t\tconst numberOfDice = Number.parseInt(diceArray[0], 10);\n\t\tconst diceToRoll = diceArray[1].replace(COMMENT_REGEX, \"\");\n\t\tconst commentsMatch = diceArray[1].match(COMMENT_REGEX);\n\t\tconst comments = commentsMatch ? commentsMatch[2] : undefined;\n\t\tconst roller = new DiceRoller();\n\t\t//remove comments if any\n\t\tfor (let i = 0; i < numberOfDice; i++) {\n\t\t\ttry {\n\t\t\t\troller.roll(diceToRoll);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new DiceTypeError(diceToRoll, \"roll\", error);\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tdice: diceToRoll,\n\t\t\tresult: roller.output,\n\t\t\tcomment: comments,\n\t\t\tcompare: compare ? compare : undefined,\n\t\t\tmodifier: modificator,\n\t\t\ttotal: roller.total,\n\t\t};\n\t}\n\tconst roller = new DiceRoller();\n\tconst diceWithoutComment = dice.replace(COMMENT_REGEX, \"\");\n\ttry {\n\t\troller.roll(diceWithoutComment);\n\t} catch (error) {\n\t\tthrow new DiceTypeError(diceWithoutComment, \"roll\", error);\n\t}\n\tconst commentMatch = dice.match(COMMENT_REGEX);\n\tconst comment = commentMatch ? commentMatch[2] : undefined;\n\treturn {\n\t\tdice,\n\t\tresult: roller.output,\n\t\tcomment,\n\t\tcompare: compare ? compare : undefined,\n\t\tmodifier: modificator,\n\t\ttotal: roller.total,\n\t};\n}\n/**\n * Evaluate a formula and replace \"^\" by \"**\" if any\n * @param {Sign} sign\n * @param {number} value\n * @param {number} total\n * @returns\n */\nexport function calculator(sign: Sign, value: number, total: number): number {\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\tif (sign === \"^\") sign = \"**\";\n\treturn evaluate(`${total} ${sign} ${value}`);\n}\n\nfunction compareResult(result: number, compare: Compare): boolean {\n\tswitch (compare.sign) {\n\t\tcase \"<\":\n\t\t\treturn result < compare.value;\n\t\tcase \">\":\n\t\t\treturn result > compare.value;\n\t\tcase \"<=\":\n\t\t\treturn result <= compare.value;\n\t\tcase \">=\":\n\t\t\treturn result >= compare.value;\n\t\tcase \"=\":\n\t\t\treturn result === compare.value;\n\t\tcase \"==\":\n\t\t\treturn result === compare.value;\n\t\tcase \"!=\":\n\t\t\treturn result !== compare.value;\n\t}\n}\n\nfunction inverseSign(\n\tsign: \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\"\n): \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\" {\n\tswitch (sign) {\n\t\tcase \"<\":\n\t\t\treturn \">\";\n\t\tcase \">\":\n\t\t\treturn \"<\";\n\t\tcase \"<=\":\n\t\t\treturn \">=\";\n\t\tcase \">=\":\n\t\t\treturn \"<=\";\n\t\tcase \"=\":\n\t\t\treturn \"!=\";\n\t\tcase \"==\":\n\t\t\treturn \"!=\";\n\t\tcase \"!=\":\n\t\t\treturn \"==\";\n\t}\n}\n\nfunction replaceInFormula(\n\telement: string,\n\tdiceResult: Resultat,\n\tcompareResult: { dice: string; compare: Compare | undefined },\n\tres: boolean\n) {\n\tconst formule = element.replace(\"µ\", `[${diceResult.total}]`);\n\tconst diceAll = element.replace(\"µ\", `[${diceResult.dice.replace(COMMENT_REGEX, \"\")}]`);\n\tconst validSign = res ? \"✓\" : \"✕\";\n\tconst invertedSign = res\n\t\t? compareResult.compare!.sign\n\t\t: inverseSign(compareResult.compare!.sign);\n\tlet evaluateRoll: unknown;\n\ttry {\n\t\tevaluateRoll = evaluate(compareResult.dice);\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\n\t} catch (error) {\n\t\tconst evaluateRoll = roll(compareResult.dice) as Resultat | undefined;\n\t\tif (evaluateRoll)\n\t\t\treturn `${validSign} ${diceAll}: ${evaluateRoll.result.split(\":\").splice(1).join(\":\")}`;\n\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\n\t}\n}\n\nfunction compareSignFormule(\n\ttoRoll: string,\n\tcompareRegex: RegExpMatchArray,\n\telement: string,\n\tdiceResult: Resultat\n) {\n\tlet results = \"\";\n\tconst compareResult = getCompare(toRoll, compareRegex);\n\tconst toCompare = `${compareResult.dice}${compareResult.compare?.sign}${compareResult.compare?.value}`;\n\tlet res: unknown;\n\ttry {\n\t\tres = evaluate(toCompare);\n\t} catch (error) {\n\t\tres = roll(toCompare);\n\t}\n\tif (typeof res === \"boolean\") {\n\t\tresults = replaceInFormula(element, diceResult, compareResult, res);\n\t} else if (res instanceof Object) {\n\t\tconst result = res as Resultat;\n\t\tif (result.compare) {\n\t\t\tconst toEvaluate = evaluate(\n\t\t\t\t`${result.total}${result.compare.sign}${result.compare.value}`\n\t\t\t);\n\t\t\tconst sign = toEvaluate ? \"✓\" : \"✕\";\n\t\t\tconst invertedSign = toEvaluate\n\t\t\t\t? result.compare.sign\n\t\t\t\t: inverseSign(result.compare.sign);\n\t\t\tconst dice = element\n\t\t\t\t.replace(\"µ\", `[${diceResult.dice.replace(COMMENT_REGEX, \"\")}]`)\n\t\t\t\t.trim();\n\t\t\tresults = `${sign} ${dice}: ${result.result.split(\":\").splice(1).join(\":\").trim()}${invertedSign}${result.compare.value}`;\n\t\t}\n\t}\n\treturn { dice: compareResult.dice, results };\n}\n\nexport function multipleFunction(dice: string): Resultat | undefined {\n\tconst results = [];\n\tconst split = dice.split(\";\");\n\tconst diceResult = roll(split[0]);\n\tif (!diceResult || !diceResult.total) return undefined;\n\tresults.push(`${diceResult.result}`);\n\n\tlet total = diceResult.total;\n\tlet comments = diceResult.comment ?? \"\";\n\tif (!total) return diceResult;\n\tfor (let element of split.slice(1)) {\n\t\tif (!element.includes(\"µ\")) {\n\t\t\tconst result = roll(element);\n\t\t\tif (!result) continue;\n\t\t\tresults.push(result.result);\n\t\t\tcontinue;\n\t\t}\n\t\t//remove comments & keep it\n\t\tconst commentMatch = element.match(COMMENT_REGEX);\n\t\telement = element.replace(COMMENT_REGEX, \"\");\n\t\tconst comment = commentMatch ? commentMatch[2] : undefined;\n\t\tif (comment) comments += ` ${comment}`;\n\t\tlet toRoll = element.replace(\"µ\", `${diceResult.total}`);\n\t\tconst compareRegex = toRoll.match(SIGN_REGEX_SPACE);\n\t\tif (compareRegex) {\n\t\t\tconst compareResult = compareSignFormule(toRoll, compareRegex, element, diceResult);\n\t\t\ttoRoll = compareResult.dice;\n\t\t\tresults.push(compareResult.results);\n\t\t} else {\n\t\t\tconst formule = element.replace(\"µ\", `[${diceResult.total}]`).trim();\n\t\t\tconst diceAll = element.replace(\n\t\t\t\t\"µ\",\n\t\t\t\t`[${diceResult.dice.replace(COMMENT_REGEX, \"\")}]`\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tconst evaluated = evaluate(toRoll);\n\t\t\t\tresults.push(`◈ ${diceAll}: ${formule} = ${evaluated}`);\n\t\t\t\ttotal += Number.parseInt(evaluated, 10);\n\t\t\t} catch (error) {\n\t\t\t\tconst evaluated = roll(toRoll);\n\t\t\t\tif (evaluated)\n\t\t\t\t\tresults.push(`◈ ${diceAll}: ${evaluated.result.split(\":\").slice(1).join(\":\")}`);\n\t\t\t\telse results.push(`◈ ${diceAll}:${formule} = ${evaluated}`);\n\t\t\t\ttotal += evaluated?.total ?? 0;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tdice: split[0],\n\t\tresult: results.join(\";\"),\n\t\tcomment: comments,\n\t\tcompare: diceResult.compare,\n\t\tmodifier: diceResult.modifier,\n\t\ttotal,\n\t};\n}\n","export class DiceTypeError extends Error {\n\tpublic readonly dice: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(dice: string, cause?: string, method?: unknown) {\n\t\tsuper(dice);\n\t\tthis.name = \"Invalid_Dice_Type\";\n\t\tthis.dice = dice;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class FormulaError extends Error {\n\tpublic readonly formula: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(formula: string, cause?: string, method?: unknown) {\n\t\tsuper(formula);\n\t\tthis.name = \"Invalid_Formula\";\n\t\tthis.formula = formula;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class MaxGreater extends Error {\n\tpublic readonly name: string;\n\tpublic readonly value: number;\n\tpublic readonly max: number;\n\n\tconstructor(value: number, max: number) {\n\t\tsuper(value.toString());\n\t\tthis.name = \"Max_Greater\";\n\t\tthis.value = value;\n\t\tthis.max = max;\n\t}\n}\n\nexport class EmptyObjectError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Empty_Object\";\n\t}\n}\n\nexport class TooManyDice extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Dice\";\n\t}\n}\n\nexport class TooManyStats extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Stats\";\n\t}\n}\n\nexport class NoStatisticsError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"No_Statistics\";\n\t}\n}\n","import { evaluate } from \"mathjs\";\nimport removeAccents from \"remove-accents\";\nimport { FormulaError } from \"./errors\";\n\n/**\n * Escape regex string\n * @param string {string}\n */\nexport function escapeRegex(string: string) {\n\treturn string.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Replace the stat name by their value using stat and after evaluate any formula using `replaceFormulaInDice`\n * @param originalDice {dice}\n * @param stats {[name: string]: number}\n */\nexport function generateStatsDice(\n\toriginalDice: string,\n\tstats?: { [name: string]: number }\n) {\n\tlet dice = originalDice;\n\tif (stats && Object.keys(stats).length > 0) {\n\t\t//damage field support adding statistic, like : 1d6 + strength\n\t\t//check if the value contains a statistic & calculate if it's okay\n\t\t//the dice will be converted before roll\n\t\tconst allStats = Object.keys(stats);\n\t\tfor (const stat of allStats) {\n\t\t\tconst regex = new RegExp(escapeRegex(removeAccents(stat)), \"gi\");\n\t\t\tif (dice.match(regex)) {\n\t\t\t\tconst statValue = stats[stat];\n\t\t\t\tdice = dice.replace(regex, statValue.toString());\n\t\t\t}\n\t\t}\n\t}\n\treturn replaceFormulaInDice(dice);\n}\n\n/**\n * Replace the {{}} in the dice string and evaluate the interior if any\n * @param dice {string}\n */\nexport function replaceFormulaInDice(dice: string) {\n\tconst formula = /(?<formula>\\{{2}(.+?)\\}{2})/gim;\n\tconst formulaMatch = formula.exec(dice);\n\tif (formulaMatch?.groups?.formula) {\n\t\tconst formula = formulaMatch.groups.formula.replaceAll(\"{{\", \"\").replaceAll(\"}}\", \"\");\n\t\ttry {\n\t\t\tconst result = evaluate(formula);\n\t\t\treturn cleanedDice(dice.replace(formulaMatch.groups.formula, result.toString()));\n\t\t} catch (error) {\n\t\t\tthrow new FormulaError(formulaMatch.groups.formula, \"replaceFormulaInDice\", error);\n\t\t}\n\t}\n\treturn cleanedDice(dice);\n}\n\n/**\n * Replace the ++ +- -- by their proper value:\n * - `++` = `+`\n * - `+-` = `-`\n * - `--` = `+`\n * @param dice {string}\n */\nexport function cleanedDice(dice: string) {\n\treturn dice.replaceAll(\"+-\", \"-\").replaceAll(\"--\", \"+\").replaceAll(\"++\", \"+\");\n}\n","/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { evaluate } from \"mathjs\";\nimport { Random } from \"random-js\";\nimport removeAccents from \"remove-accents\";\n\nimport type { Statistic, StatisticalTemplate } from \".\";\nimport { roll } from \"./dice\";\nimport { escapeRegex, replaceFormulaInDice } from \"./utils\";\nimport {\n\tDiceTypeError,\n\tEmptyObjectError,\n\tFormulaError,\n\tMaxGreater,\n\tNoStatisticsError,\n\tTooManyDice,\n\tTooManyStats,\n} from \"./errors\";\n\n/**\n * Verify if the provided dice work with random value\n * @param testDice {string}\n * @param stats {[name: string]: number}\n */\nexport function evalStatsDice(testDice: string, stats?: { [name: string]: number }) {\n\tlet dice = testDice;\n\tif (stats && Object.keys(stats).length > 0) {\n\t\tconst allStats = Object.keys(stats);\n\t\tfor (const stat of allStats) {\n\t\t\tconst regex = new RegExp(escapeRegex(removeAccents(stat)), \"gi\");\n\t\t\tif (testDice.match(regex)) {\n\t\t\t\tconst statValue = stats[stat];\n\t\t\t\tdice = testDice.replace(regex, statValue.toString());\n\t\t\t}\n\t\t}\n\t}\n\ttry {\n\t\tif (!roll(replaceFormulaInDice(dice)))\n\t\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", \"no roll result\");\n\t\treturn testDice;\n\t} catch (error) {\n\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", error);\n\t}\n}\n\n/**\n * Generate a random dice and remove the formula (+ evaluate it)\n * Used for diceDamage only\n * @param value {string}\n * @param template {StatisticalTemplate}\n * @returns\n */\nexport function diceRandomParse(value: string, template: StatisticalTemplate) {\n\tif (!template.statistics) return value;\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\tvalue = removeAccents(value);\n\tconst allStats = Object.keys(template.statistics).map((stat) =>\n\t\tremoveAccents(stat).toLowerCase()\n\t);\n\tlet newDice = value;\n\tfor (const stat of allStats) {\n\t\tconst regex = new RegExp(escapeRegex(stat), \"gi\");\n\t\tif (value.match(regex)) {\n\t\t\tlet max: undefined | number = undefined;\n\t\t\tlet min: undefined | number = undefined;\n\t\t\tconst stats = template.statistics?.[stat];\n\t\t\tif (stats) {\n\t\t\t\tmax = template.statistics[removeAccents(stat).toLowerCase()].max;\n\t\t\t\tmin = template.statistics[removeAccents(stat).toLowerCase()].min;\n\t\t\t}\n\t\t\tconst total = template.total || 100;\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\n\t\t\tnewDice = value.replace(regex, randomStatValue.toString());\n\t\t}\n\t}\n\treturn replaceFormulaInDice(newDice);\n}\n\n/**\n * Same as damageDice but for DiceType\n * @param dice {string}\n * @param template {StatisticalTemplate}\n */\nexport function diceTypeRandomParse(dice: string, template: StatisticalTemplate) {\n\tif (!template.statistics) return dice;\n\tconst firstStatNotCombinaison = Object.keys(template.statistics).find(\n\t\t(stat) => !template.statistics?.[stat].combinaison\n\t);\n\tif (!firstStatNotCombinaison) return dice;\n\tconst stats = template.statistics[firstStatNotCombinaison];\n\tconst { min, max } = stats;\n\tconst total = template.total || 100;\n\tconst randomStatValue = generateRandomStat(total, max, min);\n\treturn replaceFormulaInDice(dice.replace(\"$\", randomStatValue.toString()));\n}\n\n/**\n * Random the combinaison and evaluate it to check if everything is valid\n * @param combinaison {[name: string]: string}\n * @param stats {[name: string]: string|number}\n */\nexport function evalCombinaison(\n\tcombinaison: { [name: string]: string },\n\tstats: { [name: string]: string | number }\n) {\n\tconst newStats: { [name: string]: number } = {};\n\tfor (const [stat, combin] of Object.entries(combinaison)) {\n\t\t//replace the stats in formula\n\t\tlet formula = removeAccents(combin);\n\t\tfor (const [statName, value] of Object.entries(stats)) {\n\t\t\tconst regex = new RegExp(removeAccents(statName), \"gi\");\n\t\t\tformula = formula.replace(regex, value.toString());\n\t\t}\n\t\ttry {\n\t\t\tconst result = evaluate(formula);\n\t\t\tnewStats[stat] = result;\n\t\t} catch (error) {\n\t\t\tthrow new FormulaError(stat, \"evalCombinaison\", error);\n\t\t}\n\t}\n\treturn newStats;\n}\n\n/**\n * Evaluate one selected combinaison\n * @param combinaison {string}\n * @param stats {[name: string]: string|number}\n */\nexport function evalOneCombinaison(\n\tcombinaison: string,\n\tstats: { [name: string]: string | number }\n) {\n\tlet formula = removeAccents(combinaison);\n\tfor (const [statName, value] of Object.entries(stats)) {\n\t\tconst regex = new RegExp(removeAccents(statName), \"gi\");\n\t\tformula = formula.replace(regex, value.toString());\n\t}\n\ttry {\n\t\treturn evaluate(formula);\n\t} catch (error) {\n\t\tthrow new FormulaError(combinaison, \"evalOneCombinaison\", error);\n\t}\n}\n\n/**\n * Parse the provided JSON and verify each field to check if everything could work when rolling\n * @param {any} template\n * @returns {StatisticalTemplate}\n */\n//biome-ignore lint/suspicious/noExplicitAny: I need to use any to allow any type\nexport function verifyTemplateValue(template: any): StatisticalTemplate {\n\tconst statistiqueTemplate: StatisticalTemplate = {\n\t\tdiceType: \"\",\n\t\tstatistics: {} as Statistic,\n\t};\n\tif (!template.statistics) statistiqueTemplate.statistics = undefined;\n\telse if (template.statistics && Object.keys(template.statistics).length > 0) {\n\t\tif (Object.keys(template.statistics).length > 25) throw new TooManyStats();\n\t\tfor (const [key, value] of Object.entries(template.statistics)) {\n\t\t\tconst dataValue = value as { max?: number; min?: number; combinaison?: string };\n\t\t\tif (dataValue.max && dataValue.min && dataValue.max <= dataValue.min)\n\t\t\t\tthrow new MaxGreater(dataValue.min, dataValue.max);\n\t\t\tif (dataValue.max && dataValue.max <= 0) dataValue.max = undefined;\n\t\t\tif (dataValue.min && dataValue.min <= 0) dataValue.min = undefined;\n\t\t\tlet formula = dataValue.combinaison\n\t\t\t\t? removeAccents(dataValue.combinaison).toLowerCase()\n\t\t\t\t: undefined;\n\t\t\tformula = formula && formula.trim().length > 0 ? formula : undefined;\n\t\t\tif (!statistiqueTemplate.statistics) {\n\t\t\t\tstatistiqueTemplate.statistics = {} as Statistic;\n\t\t\t}\n\t\t\tstatistiqueTemplate.statistics[key] = {\n\t\t\t\tmax: dataValue.max,\n\t\t\t\tmin: dataValue.min,\n\t\t\t\tcombinaison: formula || undefined,\n\t\t\t};\n\t\t}\n\t}\n\tif (template.diceType) {\n\t\ttry {\n\t\t\tstatistiqueTemplate.diceType = template.diceType;\n\t\t\tconst cleanedDice = diceTypeRandomParse(template.diceType, statistiqueTemplate);\n\t\t\tconst rolled = roll(cleanedDice);\n\t\t\tif (!rolled)\n\t\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\n\t\t} catch (e) {\n\t\t\tthrow new Error((e as Error).message);\n\t\t}\n\t}\n\n\tif (template.critical && Object.keys(template.critical).length > 0) {\n\t\tstatistiqueTemplate.critical = {\n\t\t\tfailure: template.critical.failure ?? undefined,\n\t\t\tsuccess: template.critical.success ?? undefined,\n\t\t};\n\t}\n\tif (template.total) {\n\t\tif (template.total <= 0) template.total = undefined;\n\t\tstatistiqueTemplate.total = template.total;\n\t}\n\tif (template.charName) statistiqueTemplate.charName = template.charName;\n\tif (template.damage) statistiqueTemplate.damage = template.damage;\n\ttry {\n\t\ttestDiceRegistered(statistiqueTemplate);\n\t\ttestStatCombinaison(statistiqueTemplate);\n\t} catch (error) {\n\t\tthrow new Error((error as Error).message);\n\t}\n\treturn statistiqueTemplate;\n}\n\n/**\n * Test each damage roll from the template.damage\n * @param {StatisticalTemplate} template\n */\nexport function testDiceRegistered(template: StatisticalTemplate) {\n\tif (!template.damage) return;\n\tif (Object.keys(template.damage).length === 0) throw new EmptyObjectError();\n\tif (Object.keys(template.damage).length > 25) throw new TooManyDice();\n\tfor (const [name, dice] of Object.entries(template.damage)) {\n\t\tif (!dice) continue;\n\t\tconst randomDiceParsed = diceRandomParse(dice, template);\n\t\ttry {\n\t\t\tconst rolled = roll(randomDiceParsed);\n\t\t\tif (!rolled) throw new DiceTypeError(name, \"testDiceRegistered\", \"no roll result\");\n\t\t} catch (error) {\n\t\t\tthrow new DiceTypeError(name, \"testDiceRegistered\", error);\n\t\t}\n\t}\n}\n\n/**\n * Test all combinaison with generated random value\n * @param {StatisticalTemplate} template\n */\nexport function testStatCombinaison(template: StatisticalTemplate) {\n\tif (!template.statistics) return;\n\tconst onlyCombinaisonStats = Object.fromEntries(\n\t\tObject.entries(template.statistics).filter(\n\t\t\t([_, value]) => value.combinaison !== undefined\n\t\t)\n\t);\n\tconst allOtherStats = Object.fromEntries(\n\t\tObject.entries(template.statistics).filter(([_, value]) => !value.combinaison)\n\t);\n\tif (Object.keys(onlyCombinaisonStats).length === 0) return;\n\tconst allStats = Object.keys(template.statistics).filter(\n\t\t(stat) => !template.statistics![stat].combinaison\n\t);\n\tif (allStats.length === 0) throw new NoStatisticsError();\n\tconst error = [];\n\tfor (const [stat, value] of Object.entries(onlyCombinaisonStats)) {\n\t\tlet formula = value.combinaison as string;\n\t\tfor (const [other, data] of Object.entries(allOtherStats)) {\n\t\t\tconst { max, min } = data;\n\t\t\tconst total = template.total || 100;\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\n\t\t\tconst regex = new RegExp(other, \"gi\");\n\t\t\tformula = formula.replace(regex, randomStatValue.toString());\n\t\t}\n\t\ttry {\n\t\t\tevaluate(formula);\n\t\t} catch (e) {\n\t\t\terror.push(stat);\n\t\t}\n\t}\n\tif (error.length > 0) throw new FormulaError(error.join(\", \"), \"testStatCombinaison\");\n\treturn;\n}\n\n/**\n * Generate a random stat based on the template and the statistical min and max\n * @param {number|undefined} total\n * @param {number | undefined} max\n * @param {number | undefined} min\n * @returns\n */\nexport function generateRandomStat(\n\ttotal: number | undefined = 100,\n\tmax?: number,\n\tmin?: number\n) {\n\tlet randomStatValue = total + 1;\n\twhile (randomStatValue >= total) {\n\t\tconst random = new Random();\n\t\tif (max && min) randomStatValue = random.integer(min, max);\n\t\telse if (max) randomStatValue = random.integer(0, max);\n\t\telse if (min) randomStatValue = random.integer(min, total);\n\t\telse randomStatValue = random.integer(0, total);\n\t}\n\treturn randomStatValue;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,6BAA2B;AAC3B,oBAAyB;;;ACFlB,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,MAAc,OAAgB,QAAkB;AAC3D,UAAM,IAAI;AACV,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EACf;AACD;AAEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,SAAiB,OAAgB,QAAkB;AAC9D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EACf;AACD;AAEO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,OAAe,KAAa;AACvC,UAAM,MAAM,SAAS,CAAC;AACtB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,MAAM;AAAA,EACZ;AACD;AAEO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC3B;AAAA,EAEhB,cAAc;AACb,UAAM;AACN,SAAK,OAAO;AAAA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O,IAAI,KAAK,OAAO,QAAQ,aAAa,GAAG;AAC1D,YAAM,EAAE,KAAK,IAAI,IAAI;AACrB,YAAM,QAAQ,SAAS,SAAS;AAChC,YAAM,kBAAkB,mBAAmB,OAAO,KAAK,GAAG;AAC1D,YAAM,QAAQ,IAAI,OAAO,OAAO,IAAI;AACpC,gBAAU,QAAQ,QAAQ,OAAO,gBAAgB,SAAS,CAAC;AAAA,IAC5D;AACA,QAAI;AACH,mCAAS,OAAO;AAAA,IACjB,SAAS,GAAG;AACX,YAAM,KAAK,IAAI;AAAA,IAChB;AAAA,EACD;AACA,MAAI,MAAM,SAAS;AAAG,UAAM,IAAI,aAAa,MAAM,KAAK,IAAI,GAAG,qBAAqB;AACpF;AACD;AASO,SAAS,mBACf,QAA4B,KAC5B,KACA,KACC;AACD,MAAI,kBAAkB,QAAQ;AAC9B,SAAO,mBAAmB,OAAO;AAChC,UAAM,SAAS,IAAI,wBAAO;AAC1B,QAAI,OAAO;AAAK,wBAAkB,OAAO,QAAQ,KAAK,GAAG;AAAA,aAChD;AAAK,wBAAkB,OAAO,QAAQ,GAAG,GAAG;AAAA,aAC5C;AAAK,wBAAkB,OAAO,QAAQ,KAAK,KAAK;AAAA;AACpD,wBAAkB,OAAO,QAAQ,GAAG,KAAK;AAAA,EAC/C;AACA,SAAO;AACR;","names":["roller","evaluateRoll","import_mathjs","removeAccents","formula","import_mathjs","import_remove_accents","removeAccents","cleanedDice"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/dice.ts","../src/errors.ts","../src/interfaces/constant.ts","../src/utils.ts","../src/verify_template.ts"],"sourcesContent":["export * from \"./dice\";\nexport * from \"./interfaces\";\nexport * from \"./utils\";\nexport * from \"./verify_template\";\nexport * from \"./errors\";\nexport * from \"./interfaces/constant\";\n","/* eslint-disable no-useless-escape */\r\nimport { DiceRoller } from \"@dice-roller/rpg-dice-roller\";\r\nimport { evaluate } from \"mathjs\";\r\n\r\nimport type { Compare, Modifier, Resultat, Sign } from \".\";\r\nimport { DiceTypeError } from \"./errors\";\r\nimport {\r\n\tCOMMENT_REGEX,\r\n\tSIGN_REGEX,\r\n\tSIGN_REGEX_SPACE,\r\n\tSYMBOL_DICE,\r\n} from \"./interfaces/constant\";\r\n\r\nfunction getCompare(\r\n\tdice: string,\r\n\tcompareRegex: RegExpMatchArray\r\n): { dice: string; compare: Compare | undefined } {\r\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\r\n\tdice = dice.replace(SIGN_REGEX_SPACE, \"\");\r\n\tlet compare: Compare;\r\n\tconst calc = compareRegex[1];\r\n\tconst sign = calc.match(/[+-\\/*^]/)?.[0];\r\n\tconst compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];\r\n\tif (sign) {\r\n\t\tconst toCalc = calc.replace(SIGN_REGEX, \"\").replace(/\\s/g, \"\").replace(/;(.*)/, \"\");\r\n\t\tconst total = evaluate(toCalc);\r\n\t\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\r\n\t\tdice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: total,\r\n\t\t};\r\n\t} else\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: Number.parseInt(calc, 10),\r\n\t\t};\r\n\treturn { dice, compare };\r\n}\r\n\r\nfunction getModifier(dice: string) {\r\n\tconst modifier = dice.matchAll(/(\\+|-|%|\\/|\\^|\\*|\\*{2})(\\d+)/gi);\r\n\tlet modificator: Modifier | undefined;\r\n\tfor (const mod of modifier) {\r\n\t\t//calculate the modifier if multiple\r\n\t\tif (modificator) {\r\n\t\t\tconst sign = modificator.sign;\r\n\t\t\tlet value = modificator.value;\r\n\t\t\tif (sign) value = calculator(sign, value, Number.parseInt(mod[2], 10));\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue,\r\n\t\t\t};\r\n\t\t} else {\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue: Number.parseInt(mod[2], 10),\r\n\t\t\t};\r\n\t\t}\r\n\t}\r\n\treturn modificator;\r\n}\r\n\r\n/**\r\n * Parse the string provided and turn it as a readable dice for dice parser\r\n * @param dice {string}\r\n */\r\nexport function roll(dice: string): Resultat | undefined {\r\n\t//parse dice string\r\n\tif (!dice.includes(\"d\")) return undefined;\r\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\r\n\tlet compare: Compare | undefined;\r\n\tif (dice.includes(\";\") && dice.includes(\"&\")) return sharedRolls(dice);\r\n\tif (compareRegex) {\r\n\t\tconst compareResult = getCompare(dice, compareRegex);\r\n\t\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\r\n\t\tdice = compareResult.dice;\r\n\t\tcompare = compareResult.compare;\r\n\t}\r\n\tconst modificator = getModifier(dice);\r\n\r\n\tif (dice.match(/\\d+?#(.*)/)) {\r\n\t\tconst diceArray = dice.split(\"#\");\r\n\t\tconst numberOfDice = Number.parseInt(diceArray[0], 10);\r\n\t\tconst diceToRoll = diceArray[1].replace(COMMENT_REGEX, \"\");\r\n\t\tconst commentsMatch = diceArray[1].match(COMMENT_REGEX);\r\n\t\tconst comments = commentsMatch ? commentsMatch[2] : undefined;\r\n\t\tconst roller = new DiceRoller();\r\n\t\t//remove comments if any\r\n\t\tfor (let i = 0; i < numberOfDice; i++) {\r\n\t\t\ttry {\r\n\t\t\t\troller.roll(diceToRoll);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tthrow new DiceTypeError(diceToRoll, \"roll\", error);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tdice: diceToRoll,\r\n\t\t\tresult: roller.output,\r\n\t\t\tcomment: comments,\r\n\t\t\tcompare: compare ? compare : undefined,\r\n\t\t\tmodifier: modificator,\r\n\t\t\ttotal: roller.total,\r\n\t\t};\r\n\t}\r\n\tconst roller = new DiceRoller();\r\n\tconst diceWithoutComment = dice.replace(COMMENT_REGEX, \"\");\r\n\ttry {\r\n\t\troller.roll(diceWithoutComment);\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(diceWithoutComment, \"roll\", error);\r\n\t}\r\n\tconst commentMatch = dice.match(COMMENT_REGEX);\r\n\tconst comment = commentMatch ? commentMatch[2] : undefined;\r\n\treturn {\r\n\t\tdice,\r\n\t\tresult: roller.output,\r\n\t\tcomment,\r\n\t\tcompare: compare ? compare : undefined,\r\n\t\tmodifier: modificator,\r\n\t\ttotal: roller.total,\r\n\t};\r\n}\r\n/**\r\n * Evaluate a formula and replace \"^\" by \"**\" if any\r\n * @param {Sign} sign\r\n * @param {number} value\r\n * @param {number} total\r\n * @returns\r\n */\r\nexport function calculator(sign: Sign, value: number, total: number): number {\r\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\r\n\tif (sign === \"^\") sign = \"**\";\r\n\treturn evaluate(`${total} ${sign} ${value}`);\r\n}\r\n\r\nfunction inverseSign(\r\n\tsign: \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\"\r\n): \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\" {\r\n\tswitch (sign) {\r\n\t\tcase \"<\":\r\n\t\t\treturn \">\";\r\n\t\tcase \">\":\r\n\t\t\treturn \"<\";\r\n\t\tcase \"<=\":\r\n\t\t\treturn \">=\";\r\n\t\tcase \">=\":\r\n\t\t\treturn \"<=\";\r\n\t\tcase \"=\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"==\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"!=\":\r\n\t\t\treturn \"==\";\r\n\t}\r\n}\r\n\r\nfunction replaceInFormula(\r\n\telement: string,\r\n\tdiceResult: Resultat,\r\n\tcompareResult: { dice: string; compare: Compare | undefined },\r\n\tres: boolean\r\n) {\r\n\tconst { formule, diceAll } = replaceText(\r\n\t\telement,\r\n\t\tdiceResult.total ?? 0,\r\n\t\tdiceResult.dice\r\n\t);\r\n\tconst validSign = res ? \"✓\" : \"✕\";\r\n\tconst invertedSign = res\r\n\t\t? compareResult.compare!.sign\r\n\t\t: inverseSign(compareResult.compare!.sign);\r\n\tlet evaluateRoll: unknown;\r\n\ttry {\r\n\t\tevaluateRoll = evaluate(compareResult.dice);\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t} catch (error) {\r\n\t\tconst evaluateRoll = roll(compareResult.dice) as Resultat | undefined;\r\n\t\tif (evaluateRoll)\r\n\t\t\treturn `${validSign} ${diceAll}: ${evaluateRoll.result.split(\":\").splice(1).join(\":\")}`;\r\n\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t}\r\n}\r\n\r\nfunction compareSignFormule(\r\n\ttoRoll: string,\r\n\tcompareRegex: RegExpMatchArray,\r\n\telement: string,\r\n\tdiceResult: Resultat\r\n) {\r\n\tlet results = \"\";\r\n\tconst compareResult = getCompare(toRoll, compareRegex);\r\n\tconst toCompare = `${compareResult.dice}${compareResult.compare?.sign}${compareResult.compare?.value}`;\r\n\tlet res: unknown;\r\n\ttry {\r\n\t\tres = evaluate(toCompare);\r\n\t} catch (error) {\r\n\t\tres = roll(toCompare);\r\n\t}\r\n\tif (typeof res === \"boolean\") {\r\n\t\tresults = replaceInFormula(element, diceResult, compareResult, res);\r\n\t} else if (res instanceof Object) {\r\n\t\tconst diceResult = res as Resultat;\r\n\t\tif (diceResult.compare) {\r\n\t\t\tconst toEvaluate = evaluate(\r\n\t\t\t\t`${diceResult.total}${diceResult.compare.sign}${diceResult.compare.value}`\r\n\t\t\t);\r\n\t\t\tconst sign = toEvaluate ? \"✓\" : \"✕\";\r\n\t\t\tconst invertedSign = toEvaluate\r\n\t\t\t\t? diceResult.compare.sign\r\n\t\t\t\t: inverseSign(diceResult.compare.sign);\r\n\t\t\tconst dice = replaceText(element, 0, diceResult.dice).diceAll;\r\n\r\n\t\t\tresults = `${sign} ${dice}: ${diceResult.result.split(\":\").splice(1).join(\":\").trim()}${invertedSign}${diceResult.compare.value}`;\r\n\t\t}\r\n\t}\r\n\treturn { dice: compareResult.dice, results };\r\n}\r\n\r\nfunction replaceText(element: string, total: number, dice: string) {\r\n\treturn {\r\n\t\tformule: element.replace(SYMBOL_DICE, `[${total}]`).trim(),\r\n\t\tdiceAll: element.replace(SYMBOL_DICE, `[${dice.replace(COMMENT_REGEX, \"\")}]`).trim(),\r\n\t};\r\n}\r\n\r\nfunction sharedRolls(dice: string): Resultat | undefined {\r\n\t/* bulk roll are not allowed in shared rolls */\r\n\tif (dice.includes(\"#\"))\r\n\t\tthrow new DiceTypeError(\r\n\t\t\tdice,\r\n\t\t\t\"noBulkRoll\",\r\n\t\t\t\"bulk roll are not allowed in shared rolls\"\r\n\t\t);\r\n\tconst results = [];\r\n\tconst split = dice.split(\";\");\r\n\tconst diceResult = roll(split[0]);\r\n\tif (!diceResult || !diceResult.total) return undefined;\r\n\tresults.push(`${diceResult.result}`);\r\n\r\n\tlet total = diceResult.total;\r\n\tlet comments = diceResult.comment ?? \"\";\r\n\tif (!total) return diceResult;\r\n\tfor (let element of split.slice(1)) {\r\n\t\tif (!element.includes(SYMBOL_DICE)) {\r\n\t\t\tconst result = roll(element);\r\n\t\t\tif (!result) continue;\r\n\t\t\tresults.push(result.result);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\t//remove comments & keep it\r\n\t\tconst commentMatch = element.match(COMMENT_REGEX);\r\n\t\telement = element.replace(COMMENT_REGEX, \"\");\r\n\t\tconst comment = commentMatch ? commentMatch[2] : undefined;\r\n\t\tif (comment) comments += ` ${comment}`;\r\n\t\tlet toRoll = element.replace(SYMBOL_DICE, `${diceResult.total}`);\r\n\t\tconst compareRegex = toRoll.match(SIGN_REGEX_SPACE);\r\n\t\tif (compareRegex) {\r\n\t\t\tconst compareResult = compareSignFormule(toRoll, compareRegex, element, diceResult);\r\n\t\t\ttoRoll = compareResult.dice;\r\n\t\t\tresults.push(compareResult.results);\r\n\t\t} else {\r\n\t\t\tconst { formule, diceAll } = replaceText(\r\n\t\t\t\telement,\r\n\t\t\t\tdiceResult.total,\r\n\t\t\t\tdiceResult.dice\r\n\t\t\t);\r\n\r\n\t\t\ttry {\r\n\t\t\t\tconst evaluated = evaluate(toRoll);\r\n\t\t\t\tresults.push(`◈ ${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += Number.parseInt(evaluated, 10);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tconst evaluated = roll(toRoll);\r\n\t\t\t\tif (evaluated)\r\n\t\t\t\t\tresults.push(`◈ ${diceAll}: ${evaluated.result.split(\":\").slice(1).join(\":\")}`);\r\n\t\t\t\telse results.push(`◈ ${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += evaluated?.total ?? 0;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn {\r\n\t\tdice: split[0],\r\n\t\tresult: results.join(\";\"),\r\n\t\tcomment: comments,\r\n\t\tcompare: diceResult.compare,\r\n\t\tmodifier: diceResult.modifier,\r\n\t\ttotal,\r\n\t};\r\n}\r\n","export class DiceTypeError extends Error {\n\tpublic readonly dice: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(dice: string, cause?: string, method?: unknown) {\n\t\tsuper(dice);\n\t\tthis.name = \"Invalid_Dice_Type\";\n\t\tthis.dice = dice;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class FormulaError extends Error {\n\tpublic readonly formula: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(formula: string, cause?: string, method?: unknown) {\n\t\tsuper(formula);\n\t\tthis.name = \"Invalid_Formula\";\n\t\tthis.formula = formula;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class MaxGreater extends Error {\n\tpublic readonly name: string;\n\tpublic readonly value: number;\n\tpublic readonly max: number;\n\n\tconstructor(value: number, max: number) {\n\t\tsuper(value.toString());\n\t\tthis.name = \"Max_Greater\";\n\t\tthis.value = value;\n\t\tthis.max = max;\n\t}\n}\n\nexport class EmptyObjectError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Empty_Object\";\n\t}\n}\n\nexport class TooManyDice extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Dice\";\n\t}\n}\n\nexport class TooManyStats extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Stats\";\n\t}\n}\n\nexport class NoStatisticsError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"No_Statistics\";\n\t}\n}\n","export const COMMENT_REGEX = /\\s+(#|\\/{2}|\\[|\\/\\*)(.*)/;\nexport const SIGN_REGEX = /[><=!]+/;\nexport const SIGN_REGEX_SPACE = /[><=!]+(\\S+)/;\n\nexport const SYMBOL_DICE = \"&\";\n","import { evaluate } from \"mathjs\";\nimport removeAccents from \"remove-accents\";\nimport { FormulaError } from \"./errors\";\n\n/**\n * Escape regex string\n * @param string {string}\n */\nexport function escapeRegex(string: string) {\n\treturn string.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Replace the stat name by their value using stat and after evaluate any formula using `replaceFormulaInDice`\n * @param originalDice {dice}\n * @param stats {[name: string]: number}\n */\nexport function generateStatsDice(\n\toriginalDice: string,\n\tstats?: { [name: string]: number }\n) {\n\tlet dice = originalDice;\n\tif (stats && Object.keys(stats).length > 0) {\n\t\t//damage field support adding statistic, like : 1d6 + strength\n\t\t//check if the value contains a statistic & calculate if it's okay\n\t\t//the dice will be converted before roll\n\t\tconst allStats = Object.keys(stats);\n\t\tfor (const stat of allStats) {\n\t\t\tconst regex = new RegExp(escapeRegex(removeAccents(stat)), \"gi\");\n\t\t\tif (dice.match(regex)) {\n\t\t\t\tconst statValue = stats[stat];\n\t\t\t\tdice = dice.replace(regex, statValue.toString());\n\t\t\t}\n\t\t}\n\t}\n\treturn replaceFormulaInDice(dice);\n}\n\n/**\n * Replace the {{}} in the dice string and evaluate the interior if any\n * @param dice {string}\n */\nexport function replaceFormulaInDice(dice: string) {\n\tconst formula = /(?<formula>\\{{2}(.+?)\\}{2})/gim;\n\tconst formulaMatch = formula.exec(dice);\n\tif (formulaMatch?.groups?.formula) {\n\t\tconst formula = formulaMatch.groups.formula.replaceAll(\"{{\", \"\").replaceAll(\"}}\", \"\");\n\t\ttry {\n\t\t\tconst result = evaluate(formula);\n\t\t\treturn cleanedDice(dice.replace(formulaMatch.groups.formula, result.toString()));\n\t\t} catch (error) {\n\t\t\tthrow new FormulaError(formulaMatch.groups.formula, \"replaceFormulaInDice\", error);\n\t\t}\n\t}\n\treturn cleanedDice(dice);\n}\n\n/**\n * Replace the ++ +- -- by their proper value:\n * - `++` = `+`\n * - `+-` = `-`\n * - `--` = `+`\n * @param dice {string}\n */\nexport function cleanedDice(dice: string) {\n\treturn dice.replaceAll(\"+-\", \"-\").replaceAll(\"--\", \"+\").replaceAll(\"++\", \"+\");\n}\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { evaluate } from \"mathjs\";\r\nimport { Random } from \"random-js\";\r\nimport \"uniformize\";\r\n\r\nimport type { Statistic, StatisticalTemplate } from \".\";\r\nimport { roll } from \"./dice\";\r\nimport {\r\n\tDiceTypeError,\r\n\tEmptyObjectError,\r\n\tFormulaError,\r\n\tMaxGreater,\r\n\tNoStatisticsError,\r\n\tTooManyDice,\r\n\tTooManyStats,\r\n} from \"./errors\";\r\nimport { escapeRegex, replaceFormulaInDice } from \"./utils\";\r\n\r\n/**\r\n * Verify if the provided dice work with random value\r\n * @param testDice {string}\r\n * @param stats {[name: string]: number}\r\n */\r\nexport function evalStatsDice(testDice: string, stats?: { [name: string]: number }) {\r\n\tlet dice = testDice;\r\n\tif (stats && Object.keys(stats).length > 0) {\r\n\t\tconst allStats = Object.keys(stats);\r\n\t\tfor (const stat of allStats) {\r\n\t\t\tconst regex = new RegExp(escapeRegex(stat.standardize()), \"gi\");\r\n\t\t\tif (testDice.match(regex)) {\r\n\t\t\t\tconst statValue = stats[stat];\r\n\t\t\t\tdice = testDice.replace(regex, statValue.toString());\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\ttry {\r\n\t\tif (!roll(replaceFormulaInDice(dice)))\r\n\t\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", \"no roll result\");\r\n\t\treturn testDice;\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", error);\r\n\t}\r\n}\r\n\r\n/**\r\n * Generate a random dice and remove the formula (+ evaluate it)\r\n * Used for diceDamage only\r\n * @param value {string}\r\n * @param template {StatisticalTemplate}\r\n * @returns\r\n */\r\nexport function diceRandomParse(value: string, template: StatisticalTemplate) {\r\n\tif (!template.statistics) return value;\r\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\r\n\tvalue = value.standardize();\r\n\tconst allStats = Object.keys(template.statistics).map((stat) => stat.standardize());\r\n\tlet newDice = value;\r\n\tfor (const stat of allStats) {\r\n\t\tconst regex = new RegExp(escapeRegex(stat), \"gi\");\r\n\t\tif (value.match(regex)) {\r\n\t\t\tlet max: undefined | number = undefined;\r\n\t\t\tlet min: undefined | number = undefined;\r\n\t\t\tconst stats = template.statistics?.[stat];\r\n\t\t\tif (stats) {\r\n\t\t\t\tmax = template.statistics[stat.standardize()].max;\r\n\t\t\t\tmin = template.statistics[stat.standardize()].min;\r\n\t\t\t}\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tnewDice = value.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t}\r\n\treturn replaceFormulaInDice(newDice);\r\n}\r\n\r\n/**\r\n * Same as damageDice but for DiceType\r\n * @param dice {string}\r\n * @param template {StatisticalTemplate}\r\n */\r\nexport function diceTypeRandomParse(dice: string, template: StatisticalTemplate) {\r\n\tif (!template.statistics) return dice;\r\n\tconst firstStatNotcombinaison = Object.keys(template.statistics).find(\r\n\t\t(stat) => !template.statistics?.[stat].combinaison\r\n\t);\r\n\tif (!firstStatNotcombinaison) return dice;\r\n\tconst stats = template.statistics[firstStatNotcombinaison];\r\n\tconst { min, max } = stats;\r\n\tconst total = template.total || 100;\r\n\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\treturn replaceFormulaInDice(dice.replace(\"$\", randomStatValue.toString()));\r\n}\r\n\r\n/**\r\n * Random the combinaison and evaluate it to check if everything is valid\r\n * @param combinaison {[name: string]: string}\r\n * @param stats {[name: string]: string|number}\r\n */\r\nexport function evalCombinaison(\r\n\tcombinaison: { [name: string]: string },\r\n\tstats: { [name: string]: string | number }\r\n) {\r\n\tconst newStats: { [name: string]: number } = {};\r\n\tfor (const [stat, combin] of Object.entries(combinaison)) {\r\n\t\t//replace the stats in formula\r\n\t\tlet formula = combin.standardize();\r\n\t\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\t\tformula = formula.replace(regex, value.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tnewStats[stat] = evaluate(formula);\r\n\t\t} catch (error) {\r\n\t\t\tthrow new FormulaError(stat, \"evalCombinaison\", error);\r\n\t\t}\r\n\t}\r\n\treturn newStats;\r\n}\r\n\r\n/**\r\n * Evaluate one selected combinaison\r\n * @param combinaison {string}\r\n * @param stats {[name: string]: string|number}\r\n */\r\nexport function evalOneCombinaison(\r\n\tcombinaison: string,\r\n\tstats: { [name: string]: string | number }\r\n) {\r\n\tlet formula = combinaison.standardize();\r\n\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\tformula = formula.replace(regex, value.toString());\r\n\t}\r\n\ttry {\r\n\t\treturn evaluate(formula);\r\n\t} catch (error) {\r\n\t\tthrow new FormulaError(combinaison, \"evalOneCombinaison\", error);\r\n\t}\r\n}\r\n\r\n/**\r\n * Parse the provided JSON and verify each field to check if everything could work when rolling\r\n * @param {any} template\r\n * @returns {StatisticalTemplate}\r\n */\r\n//biome-ignore lint/suspicious/noExplicitAny: I need to use any to allow any type\r\nexport function verifyTemplateValue(template: any): StatisticalTemplate {\r\n\tconst statistiqueTemplate: StatisticalTemplate = {\r\n\t\tdiceType: \"\",\r\n\t\tstatistics: {} as Statistic,\r\n\t};\r\n\tif (!template.statistics) statistiqueTemplate.statistics = undefined;\r\n\telse if (template.statistics && Object.keys(template.statistics).length > 0) {\r\n\t\tif (Object.keys(template.statistics).length > 25) throw new TooManyStats();\r\n\t\tfor (const [key, value] of Object.entries(template.statistics)) {\r\n\t\t\tconst dataValue = value as { max?: number; min?: number; combinaison?: string };\r\n\t\t\tif (dataValue.max && dataValue.min && dataValue.max <= dataValue.min)\r\n\t\t\t\tthrow new MaxGreater(dataValue.min, dataValue.max);\r\n\t\t\tif (dataValue.max && dataValue.max <= 0) dataValue.max = undefined;\r\n\t\t\tif (dataValue.min && dataValue.min <= 0) dataValue.min = undefined;\r\n\t\t\tlet formula = dataValue.combinaison\r\n\t\t\t\t? dataValue.combinaison.standardize()\r\n\t\t\t\t: undefined;\r\n\t\t\tformula = formula && formula.trim().length > 0 ? formula : undefined;\r\n\t\t\tif (!statistiqueTemplate.statistics) {\r\n\t\t\t\tstatistiqueTemplate.statistics = {} as Statistic;\r\n\t\t\t}\r\n\t\t\tstatistiqueTemplate.statistics[key] = {\r\n\t\t\t\tmax: dataValue.max,\r\n\t\t\t\tmin: dataValue.min,\r\n\t\t\t\tcombinaison: formula || undefined,\r\n\t\t\t};\r\n\t\t}\r\n\t}\r\n\tif (template.diceType) {\r\n\t\tstatistiqueTemplate.diceType = template.diceType;\r\n\t\tconst cleanedDice = diceTypeRandomParse(template.diceType, statistiqueTemplate);\r\n\t\tconst rolled = roll(cleanedDice);\r\n\t\tif (!rolled)\r\n\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\r\n\t}\r\n\r\n\tif (template.critical && Object.keys(template.critical).length > 0) {\r\n\t\tstatistiqueTemplate.critical = {\r\n\t\t\tfailure: template.critical.failure ?? undefined,\r\n\t\t\tsuccess: template.critical.success ?? undefined,\r\n\t\t};\r\n\t}\r\n\tif (template.total) {\r\n\t\tif (template.total <= 0) template.total = undefined;\r\n\t\tstatistiqueTemplate.total = template.total;\r\n\t}\r\n\tif (template.charName) statistiqueTemplate.charName = template.charName;\r\n\tif (template.damage) statistiqueTemplate.damage = template.damage;\r\n\ttestDiceRegistered(statistiqueTemplate);\r\n\ttestStatCombinaison(statistiqueTemplate);\r\n\treturn statistiqueTemplate;\r\n}\r\n\r\n/**\r\n * Test each damage roll from the template.damage\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testDiceRegistered(template: StatisticalTemplate) {\r\n\tif (!template.damage) return;\r\n\tif (Object.keys(template.damage).length === 0) throw new EmptyObjectError();\r\n\tif (Object.keys(template.damage).length > 25) throw new TooManyDice();\r\n\tfor (const [name, dice] of Object.entries(template.damage)) {\r\n\t\tif (!dice) continue;\r\n\t\tconst randomDiceParsed = diceRandomParse(dice, template);\r\n\t\ttry {\r\n\t\t\tconst rolled = roll(randomDiceParsed);\r\n\t\t\tif (!rolled) throw new DiceTypeError(name, \"testDiceRegistered\", \"no roll result\");\r\n\t\t} catch (error) {\r\n\t\t\tthrow new DiceTypeError(name, \"testDiceRegistered\", error);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/**\r\n * Test all combinaison with generated random value\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testStatCombinaison(template: StatisticalTemplate) {\r\n\tif (!template.statistics) return;\r\n\tconst onlycombinaisonStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(\r\n\t\t\t([_, value]) => value.combinaison !== undefined\r\n\t\t)\r\n\t);\r\n\tconst allOtherStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(([_, value]) => !value.combinaison)\r\n\t);\r\n\tif (Object.keys(onlycombinaisonStats).length === 0) return;\r\n\tconst allStats = Object.keys(template.statistics).filter(\r\n\t\t(stat) => !template.statistics![stat].combinaison\r\n\t);\r\n\tif (allStats.length === 0) throw new NoStatisticsError();\r\n\tconst error = [];\r\n\tfor (const [stat, value] of Object.entries(onlycombinaisonStats)) {\r\n\t\tlet formula = value.combinaison as string;\r\n\t\tfor (const [other, data] of Object.entries(allOtherStats)) {\r\n\t\t\tconst { max, min } = data;\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tconst regex = new RegExp(other, \"gi\");\r\n\t\t\tformula = formula.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tevaluate(formula);\r\n\t\t} catch (e) {\r\n\t\t\terror.push(stat);\r\n\t\t}\r\n\t}\r\n\tif (error.length > 0) throw new FormulaError(error.join(\", \"), \"testStatCombinaison\");\r\n\treturn;\r\n}\r\n\r\n/**\r\n * Generate a random stat based on the template and the statistical min and max\r\n * @param {number|undefined} total\r\n * @param {number | undefined} max\r\n * @param {number | undefined} min\r\n * @returns\r\n */\r\nexport function generateRandomStat(\r\n\ttotal: number | undefined = 100,\r\n\tmax?: number,\r\n\tmin?: number\r\n) {\r\n\tlet randomStatValue = total + 1;\r\n\twhile (randomStatValue >= total) {\r\n\t\tconst random = new Random();\r\n\t\tif (max && min) randomStatValue = random.integer(min, max);\r\n\t\telse if (max) randomStatValue = random.integer(0, max);\r\n\t\telse if (min) randomStatValue = random.integer(min, total);\r\n\t\telse randomStatValue = random.integer(0, total);\r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S;AAAG,UAAM,IAAI,aAAa,MAAM,KAAK,IAAI,GAAG,qBAAqB;AACpF;AACD;AASO,SAAS,mBACf,QAA4B,KAC5B,KACA,KACC;AACD,MAAI,kBAAkB,QAAQ;AAC9B,SAAO,mBAAmB,OAAO;AAChC,UAAM,SAAS,IAAI,wBAAO;AAC1B,QAAI,OAAO;AAAK,wBAAkB,OAAO,QAAQ,KAAK,GAAG;AAAA,aAChD;AAAK,wBAAkB,OAAO,QAAQ,GAAG,GAAG;AAAA,aAC5C;AAAK,wBAAkB,OAAO,QAAQ,KAAK,KAAK;AAAA;AACpD,wBAAkB,OAAO,QAAQ,GAAG,KAAK;AAAA,EAC/C;AACA,SAAO;AACR;","names":["roller","evaluateRoll","diceResult","import_mathjs","removeAccents","formula","import_mathjs","cleanedDice"]}
package/dist/index.mjs CHANGED
@@ -67,15 +67,18 @@ var NoStatisticsError = class extends Error {
67
67
  }
68
68
  };
69
69
 
70
- // src/dice.ts
70
+ // src/interfaces/constant.ts
71
71
  var COMMENT_REGEX = /\s+(#|\/{2}|\[|\/\*)(.*)/;
72
72
  var SIGN_REGEX = /[><=!]+/;
73
73
  var SIGN_REGEX_SPACE = /[><=!]+(\S+)/;
74
+ var SYMBOL_DICE = "&";
75
+
76
+ // src/dice.ts
74
77
  function getCompare(dice, compareRegex) {
75
78
  dice = dice.replace(SIGN_REGEX_SPACE, "");
76
79
  let compare;
77
80
  const calc = compareRegex[1];
78
- const sign = calc.match(/[+-\/\*\^]/)?.[0];
81
+ const sign = calc.match(/[+-\/*^]/)?.[0];
79
82
  const compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];
80
83
  if (sign) {
81
84
  const toCalc = calc.replace(SIGN_REGEX, "").replace(/\s/g, "").replace(/;(.*)/, "");
@@ -93,7 +96,7 @@ function getCompare(dice, compareRegex) {
93
96
  return { dice, compare };
94
97
  }
95
98
  function getModifier(dice) {
96
- const modifier = dice.matchAll(/(\+|\-|%|\/|\^|\*|\*{2})(\d+)/gi);
99
+ const modifier = dice.matchAll(/(\+|-|%|\/|\^|\*|\*{2})(\d+)/gi);
97
100
  let modificator;
98
101
  for (const mod of modifier) {
99
102
  if (modificator) {
@@ -119,8 +122,8 @@ function roll(dice) {
119
122
  return void 0;
120
123
  const compareRegex = dice.match(SIGN_REGEX_SPACE);
121
124
  let compare;
122
- if (dice.includes(";") && dice.includes("\xB5"))
123
- return multipleFunction(dice);
125
+ if (dice.includes(";") && dice.includes("&"))
126
+ return sharedRolls(dice);
124
127
  if (compareRegex) {
125
128
  const compareResult = getCompare(dice, compareRegex);
126
129
  dice = compareResult.dice;
@@ -192,8 +195,11 @@ function inverseSign(sign) {
192
195
  }
193
196
  }
194
197
  function replaceInFormula(element, diceResult, compareResult, res) {
195
- const formule = element.replace("\xB5", `[${diceResult.total}]`);
196
- const diceAll = element.replace("\xB5", `[${diceResult.dice.replace(COMMENT_REGEX, "")}]`);
198
+ const { formule, diceAll } = replaceText(
199
+ element,
200
+ diceResult.total ?? 0,
201
+ diceResult.dice
202
+ );
197
203
  const validSign = res ? "\u2713" : "\u2715";
198
204
  const invertedSign = res ? compareResult.compare.sign : inverseSign(compareResult.compare.sign);
199
205
  let evaluateRoll;
@@ -220,20 +226,32 @@ function compareSignFormule(toRoll, compareRegex, element, diceResult) {
220
226
  if (typeof res === "boolean") {
221
227
  results = replaceInFormula(element, diceResult, compareResult, res);
222
228
  } else if (res instanceof Object) {
223
- const result = res;
224
- if (result.compare) {
229
+ const diceResult2 = res;
230
+ if (diceResult2.compare) {
225
231
  const toEvaluate = evaluate(
226
- `${result.total}${result.compare.sign}${result.compare.value}`
232
+ `${diceResult2.total}${diceResult2.compare.sign}${diceResult2.compare.value}`
227
233
  );
228
234
  const sign = toEvaluate ? "\u2713" : "\u2715";
229
- const invertedSign = toEvaluate ? result.compare.sign : inverseSign(result.compare.sign);
230
- const dice = element.replace("\xB5", `[${diceResult.dice.replace(COMMENT_REGEX, "")}]`).trim();
231
- results = `${sign} ${dice}: ${result.result.split(":").splice(1).join(":").trim()}${invertedSign}${result.compare.value}`;
235
+ const invertedSign = toEvaluate ? diceResult2.compare.sign : inverseSign(diceResult2.compare.sign);
236
+ const dice = replaceText(element, 0, diceResult2.dice).diceAll;
237
+ results = `${sign} ${dice}: ${diceResult2.result.split(":").splice(1).join(":").trim()}${invertedSign}${diceResult2.compare.value}`;
232
238
  }
233
239
  }
234
240
  return { dice: compareResult.dice, results };
235
241
  }
236
- function multipleFunction(dice) {
242
+ function replaceText(element, total, dice) {
243
+ return {
244
+ formule: element.replace(SYMBOL_DICE, `[${total}]`).trim(),
245
+ diceAll: element.replace(SYMBOL_DICE, `[${dice.replace(COMMENT_REGEX, "")}]`).trim()
246
+ };
247
+ }
248
+ function sharedRolls(dice) {
249
+ if (dice.includes("#"))
250
+ throw new DiceTypeError(
251
+ dice,
252
+ "noBulkRoll",
253
+ "bulk roll are not allowed in shared rolls"
254
+ );
237
255
  const results = [];
238
256
  const split = dice.split(";");
239
257
  const diceResult = roll(split[0]);
@@ -245,7 +263,7 @@ function multipleFunction(dice) {
245
263
  if (!total)
246
264
  return diceResult;
247
265
  for (let element of split.slice(1)) {
248
- if (!element.includes("\xB5")) {
266
+ if (!element.includes(SYMBOL_DICE)) {
249
267
  const result = roll(element);
250
268
  if (!result)
251
269
  continue;
@@ -257,17 +275,17 @@ function multipleFunction(dice) {
257
275
  const comment = commentMatch ? commentMatch[2] : void 0;
258
276
  if (comment)
259
277
  comments += ` ${comment}`;
260
- let toRoll = element.replace("\xB5", `${diceResult.total}`);
278
+ let toRoll = element.replace(SYMBOL_DICE, `${diceResult.total}`);
261
279
  const compareRegex = toRoll.match(SIGN_REGEX_SPACE);
262
280
  if (compareRegex) {
263
281
  const compareResult = compareSignFormule(toRoll, compareRegex, element, diceResult);
264
282
  toRoll = compareResult.dice;
265
283
  results.push(compareResult.results);
266
284
  } else {
267
- const formule = element.replace("\xB5", `[${diceResult.total}]`).trim();
268
- const diceAll = element.replace(
269
- "\xB5",
270
- `[${diceResult.dice.replace(COMMENT_REGEX, "")}]`
285
+ const { formule, diceAll } = replaceText(
286
+ element,
287
+ diceResult.total,
288
+ diceResult.dice
271
289
  );
272
290
  try {
273
291
  const evaluated = evaluate(toRoll);
@@ -278,7 +296,7 @@ function multipleFunction(dice) {
278
296
  if (evaluated)
279
297
  results.push(`\u25C8 ${diceAll}: ${evaluated.result.split(":").slice(1).join(":")}`);
280
298
  else
281
- results.push(`\u25C8 ${diceAll}:${formule} = ${evaluated}`);
299
+ results.push(`\u25C8 ${diceAll}: ${formule} = ${evaluated}`);
282
300
  total += evaluated?.total ?? 0;
283
301
  }
284
302
  }
@@ -334,13 +352,13 @@ function cleanedDice(dice) {
334
352
  // src/verify_template.ts
335
353
  import { evaluate as evaluate3 } from "mathjs";
336
354
  import { Random } from "random-js";
337
- import removeAccents2 from "remove-accents";
355
+ import "uniformize";
338
356
  function evalStatsDice(testDice, stats) {
339
357
  let dice = testDice;
340
358
  if (stats && Object.keys(stats).length > 0) {
341
359
  const allStats = Object.keys(stats);
342
360
  for (const stat of allStats) {
343
- const regex = new RegExp(escapeRegex(removeAccents2(stat)), "gi");
361
+ const regex = new RegExp(escapeRegex(stat.standardize()), "gi");
344
362
  if (testDice.match(regex)) {
345
363
  const statValue = stats[stat];
346
364
  dice = testDice.replace(regex, statValue.toString());
@@ -358,10 +376,8 @@ function evalStatsDice(testDice, stats) {
358
376
  function diceRandomParse(value, template) {
359
377
  if (!template.statistics)
360
378
  return value;
361
- value = removeAccents2(value);
362
- const allStats = Object.keys(template.statistics).map(
363
- (stat) => removeAccents2(stat).toLowerCase()
364
- );
379
+ value = value.standardize();
380
+ const allStats = Object.keys(template.statistics).map((stat) => stat.standardize());
365
381
  let newDice = value;
366
382
  for (const stat of allStats) {
367
383
  const regex = new RegExp(escapeRegex(stat), "gi");
@@ -370,8 +386,8 @@ function diceRandomParse(value, template) {
370
386
  let min = void 0;
371
387
  const stats = template.statistics?.[stat];
372
388
  if (stats) {
373
- max = template.statistics[removeAccents2(stat).toLowerCase()].max;
374
- min = template.statistics[removeAccents2(stat).toLowerCase()].min;
389
+ max = template.statistics[stat.standardize()].max;
390
+ min = template.statistics[stat.standardize()].min;
375
391
  }
376
392
  const total = template.total || 100;
377
393
  const randomStatValue = generateRandomStat(total, max, min);
@@ -383,12 +399,12 @@ function diceRandomParse(value, template) {
383
399
  function diceTypeRandomParse(dice, template) {
384
400
  if (!template.statistics)
385
401
  return dice;
386
- const firstStatNotCombinaison = Object.keys(template.statistics).find(
402
+ const firstStatNotcombinaison = Object.keys(template.statistics).find(
387
403
  (stat) => !template.statistics?.[stat].combinaison
388
404
  );
389
- if (!firstStatNotCombinaison)
405
+ if (!firstStatNotcombinaison)
390
406
  return dice;
391
- const stats = template.statistics[firstStatNotCombinaison];
407
+ const stats = template.statistics[firstStatNotcombinaison];
392
408
  const { min, max } = stats;
393
409
  const total = template.total || 100;
394
410
  const randomStatValue = generateRandomStat(total, max, min);
@@ -397,14 +413,13 @@ function diceTypeRandomParse(dice, template) {
397
413
  function evalCombinaison(combinaison, stats) {
398
414
  const newStats = {};
399
415
  for (const [stat, combin] of Object.entries(combinaison)) {
400
- let formula = removeAccents2(combin);
416
+ let formula = combin.standardize();
401
417
  for (const [statName, value] of Object.entries(stats)) {
402
- const regex = new RegExp(removeAccents2(statName), "gi");
418
+ const regex = new RegExp(statName.standardize(), "gi");
403
419
  formula = formula.replace(regex, value.toString());
404
420
  }
405
421
  try {
406
- const result = evaluate3(formula);
407
- newStats[stat] = result;
422
+ newStats[stat] = evaluate3(formula);
408
423
  } catch (error) {
409
424
  throw new FormulaError(stat, "evalCombinaison", error);
410
425
  }
@@ -412,9 +427,9 @@ function evalCombinaison(combinaison, stats) {
412
427
  return newStats;
413
428
  }
414
429
  function evalOneCombinaison(combinaison, stats) {
415
- let formula = removeAccents2(combinaison);
430
+ let formula = combinaison.standardize();
416
431
  for (const [statName, value] of Object.entries(stats)) {
417
- const regex = new RegExp(removeAccents2(statName), "gi");
432
+ const regex = new RegExp(statName.standardize(), "gi");
418
433
  formula = formula.replace(regex, value.toString());
419
434
  }
420
435
  try {
@@ -441,7 +456,7 @@ function verifyTemplateValue(template) {
441
456
  dataValue.max = void 0;
442
457
  if (dataValue.min && dataValue.min <= 0)
443
458
  dataValue.min = void 0;
444
- let formula = dataValue.combinaison ? removeAccents2(dataValue.combinaison).toLowerCase() : void 0;
459
+ let formula = dataValue.combinaison ? dataValue.combinaison.standardize() : void 0;
445
460
  formula = formula && formula.trim().length > 0 ? formula : void 0;
446
461
  if (!statistiqueTemplate.statistics) {
447
462
  statistiqueTemplate.statistics = {};
@@ -454,15 +469,11 @@ function verifyTemplateValue(template) {
454
469
  }
455
470
  }
456
471
  if (template.diceType) {
457
- try {
458
- statistiqueTemplate.diceType = template.diceType;
459
- const cleanedDice2 = diceTypeRandomParse(template.diceType, statistiqueTemplate);
460
- const rolled = roll(cleanedDice2);
461
- if (!rolled)
462
- throw new DiceTypeError(cleanedDice2, "verifyTemplateValue", "no roll result");
463
- } catch (e) {
464
- throw new Error(e.message);
465
- }
472
+ statistiqueTemplate.diceType = template.diceType;
473
+ const cleanedDice2 = diceTypeRandomParse(template.diceType, statistiqueTemplate);
474
+ const rolled = roll(cleanedDice2);
475
+ if (!rolled)
476
+ throw new DiceTypeError(cleanedDice2, "verifyTemplateValue", "no roll result");
466
477
  }
467
478
  if (template.critical && Object.keys(template.critical).length > 0) {
468
479
  statistiqueTemplate.critical = {
@@ -479,12 +490,8 @@ function verifyTemplateValue(template) {
479
490
  statistiqueTemplate.charName = template.charName;
480
491
  if (template.damage)
481
492
  statistiqueTemplate.damage = template.damage;
482
- try {
483
- testDiceRegistered(statistiqueTemplate);
484
- testStatCombinaison(statistiqueTemplate);
485
- } catch (error) {
486
- throw new Error(error.message);
487
- }
493
+ testDiceRegistered(statistiqueTemplate);
494
+ testStatCombinaison(statistiqueTemplate);
488
495
  return statistiqueTemplate;
489
496
  }
490
497
  function testDiceRegistered(template) {
@@ -510,7 +517,7 @@ function testDiceRegistered(template) {
510
517
  function testStatCombinaison(template) {
511
518
  if (!template.statistics)
512
519
  return;
513
- const onlyCombinaisonStats = Object.fromEntries(
520
+ const onlycombinaisonStats = Object.fromEntries(
514
521
  Object.entries(template.statistics).filter(
515
522
  ([_, value]) => value.combinaison !== void 0
516
523
  )
@@ -518,7 +525,7 @@ function testStatCombinaison(template) {
518
525
  const allOtherStats = Object.fromEntries(
519
526
  Object.entries(template.statistics).filter(([_, value]) => !value.combinaison)
520
527
  );
521
- if (Object.keys(onlyCombinaisonStats).length === 0)
528
+ if (Object.keys(onlycombinaisonStats).length === 0)
522
529
  return;
523
530
  const allStats = Object.keys(template.statistics).filter(
524
531
  (stat) => !template.statistics[stat].combinaison
@@ -526,7 +533,7 @@ function testStatCombinaison(template) {
526
533
  if (allStats.length === 0)
527
534
  throw new NoStatisticsError();
528
535
  const error = [];
529
- for (const [stat, value] of Object.entries(onlyCombinaisonStats)) {
536
+ for (const [stat, value] of Object.entries(onlycombinaisonStats)) {
530
537
  let formula = value.combinaison;
531
538
  for (const [other, data] of Object.entries(allOtherStats)) {
532
539
  const { max, min } = data;
@@ -567,6 +574,9 @@ export {
567
574
  FormulaError,
568
575
  MaxGreater,
569
576
  NoStatisticsError,
577
+ SIGN_REGEX,
578
+ SIGN_REGEX_SPACE,
579
+ SYMBOL_DICE,
570
580
  TooManyDice,
571
581
  TooManyStats,
572
582
  calculator,
@@ -579,7 +589,6 @@ export {
579
589
  evalStatsDice,
580
590
  generateRandomStat,
581
591
  generateStatsDice,
582
- multipleFunction,
583
592
  replaceFormulaInDice,
584
593
  roll,
585
594
  testDiceRegistered,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dice.ts","../src/errors.ts","../src/utils.ts","../src/verify_template.ts"],"sourcesContent":["/* eslint-disable no-useless-escape */\nimport { DiceRoller } from \"@dice-roller/rpg-dice-roller\";\nimport { evaluate } from \"mathjs\";\n\nimport type { Compare, Modifier, Resultat, Sign } from \".\";\nimport { DiceTypeError } from \"./errors\";\n\nexport const COMMENT_REGEX = /\\s+(#|\\/{2}|\\[|\\/\\*)(.*)/;\nconst SIGN_REGEX = /[><=!]+/;\nconst SIGN_REGEX_SPACE = /[><=!]+(\\S+)/;\n\nfunction getCompare(\n\tdice: string,\n\tcompareRegex: RegExpMatchArray\n): { dice: string; compare: Compare | undefined } {\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\tdice = dice.replace(SIGN_REGEX_SPACE, \"\");\n\tlet compare: Compare;\n\tconst calc = compareRegex[1];\n\tconst sign = calc.match(/[+-\\/\\*\\^]/)?.[0];\n\tconst compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];\n\tif (sign) {\n\t\tconst toCalc = calc.replace(SIGN_REGEX, \"\").replace(/\\s/g, \"\").replace(/;(.*)/, \"\");\n\t\tconst total = evaluate(toCalc);\n\t\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\t\tdice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);\n\t\tcompare = {\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\n\t\t\tvalue: total,\n\t\t};\n\t} else\n\t\tcompare = {\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\n\t\t\tvalue: Number.parseInt(calc, 10),\n\t\t};\n\treturn { dice, compare };\n}\n\nfunction getModifier(dice: string) {\n\tconst modifier = dice.matchAll(/(\\+|\\-|%|\\/|\\^|\\*|\\*{2})(\\d+)/gi);\n\tlet modificator: Modifier | undefined;\n\tfor (const mod of modifier) {\n\t\t//calculate the modifier if multiple\n\t\tif (modificator) {\n\t\t\tconst sign = modificator.sign;\n\t\t\tlet value = modificator.value;\n\t\t\tif (sign) value = calculator(sign, value, Number.parseInt(mod[2], 10));\n\t\t\tmodificator = {\n\t\t\t\tsign: mod[1] as Sign,\n\t\t\t\tvalue,\n\t\t\t};\n\t\t} else {\n\t\t\tmodificator = {\n\t\t\t\tsign: mod[1] as Sign,\n\t\t\t\tvalue: Number.parseInt(mod[2], 10),\n\t\t\t};\n\t\t}\n\t}\n\treturn modificator;\n}\n\n/**\n * Parse the string provided and turn it as a readable dice for dice parser\n * @param dice {string}\n */\nexport function roll(dice: string): Resultat | undefined {\n\t//parse dice string\n\tif (!dice.includes(\"d\")) return undefined;\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\n\tlet compare: Compare | undefined;\n\tif (dice.includes(\";\") && dice.includes(\"µ\")) return multipleFunction(dice);\n\tif (compareRegex) {\n\t\tconst compareResult = getCompare(dice, compareRegex);\n\t\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\t\tdice = compareResult.dice;\n\t\tcompare = compareResult.compare;\n\t}\n\tconst modificator = getModifier(dice);\n\n\tif (dice.match(/\\d+?#(.*)/)) {\n\t\tconst diceArray = dice.split(\"#\");\n\t\tconst numberOfDice = Number.parseInt(diceArray[0], 10);\n\t\tconst diceToRoll = diceArray[1].replace(COMMENT_REGEX, \"\");\n\t\tconst commentsMatch = diceArray[1].match(COMMENT_REGEX);\n\t\tconst comments = commentsMatch ? commentsMatch[2] : undefined;\n\t\tconst roller = new DiceRoller();\n\t\t//remove comments if any\n\t\tfor (let i = 0; i < numberOfDice; i++) {\n\t\t\ttry {\n\t\t\t\troller.roll(diceToRoll);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new DiceTypeError(diceToRoll, \"roll\", error);\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tdice: diceToRoll,\n\t\t\tresult: roller.output,\n\t\t\tcomment: comments,\n\t\t\tcompare: compare ? compare : undefined,\n\t\t\tmodifier: modificator,\n\t\t\ttotal: roller.total,\n\t\t};\n\t}\n\tconst roller = new DiceRoller();\n\tconst diceWithoutComment = dice.replace(COMMENT_REGEX, \"\");\n\ttry {\n\t\troller.roll(diceWithoutComment);\n\t} catch (error) {\n\t\tthrow new DiceTypeError(diceWithoutComment, \"roll\", error);\n\t}\n\tconst commentMatch = dice.match(COMMENT_REGEX);\n\tconst comment = commentMatch ? commentMatch[2] : undefined;\n\treturn {\n\t\tdice,\n\t\tresult: roller.output,\n\t\tcomment,\n\t\tcompare: compare ? compare : undefined,\n\t\tmodifier: modificator,\n\t\ttotal: roller.total,\n\t};\n}\n/**\n * Evaluate a formula and replace \"^\" by \"**\" if any\n * @param {Sign} sign\n * @param {number} value\n * @param {number} total\n * @returns\n */\nexport function calculator(sign: Sign, value: number, total: number): number {\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\tif (sign === \"^\") sign = \"**\";\n\treturn evaluate(`${total} ${sign} ${value}`);\n}\n\nfunction compareResult(result: number, compare: Compare): boolean {\n\tswitch (compare.sign) {\n\t\tcase \"<\":\n\t\t\treturn result < compare.value;\n\t\tcase \">\":\n\t\t\treturn result > compare.value;\n\t\tcase \"<=\":\n\t\t\treturn result <= compare.value;\n\t\tcase \">=\":\n\t\t\treturn result >= compare.value;\n\t\tcase \"=\":\n\t\t\treturn result === compare.value;\n\t\tcase \"==\":\n\t\t\treturn result === compare.value;\n\t\tcase \"!=\":\n\t\t\treturn result !== compare.value;\n\t}\n}\n\nfunction inverseSign(\n\tsign: \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\"\n): \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\" {\n\tswitch (sign) {\n\t\tcase \"<\":\n\t\t\treturn \">\";\n\t\tcase \">\":\n\t\t\treturn \"<\";\n\t\tcase \"<=\":\n\t\t\treturn \">=\";\n\t\tcase \">=\":\n\t\t\treturn \"<=\";\n\t\tcase \"=\":\n\t\t\treturn \"!=\";\n\t\tcase \"==\":\n\t\t\treturn \"!=\";\n\t\tcase \"!=\":\n\t\t\treturn \"==\";\n\t}\n}\n\nfunction replaceInFormula(\n\telement: string,\n\tdiceResult: Resultat,\n\tcompareResult: { dice: string; compare: Compare | undefined },\n\tres: boolean\n) {\n\tconst formule = element.replace(\"µ\", `[${diceResult.total}]`);\n\tconst diceAll = element.replace(\"µ\", `[${diceResult.dice.replace(COMMENT_REGEX, \"\")}]`);\n\tconst validSign = res ? \"✓\" : \"✕\";\n\tconst invertedSign = res\n\t\t? compareResult.compare!.sign\n\t\t: inverseSign(compareResult.compare!.sign);\n\tlet evaluateRoll: unknown;\n\ttry {\n\t\tevaluateRoll = evaluate(compareResult.dice);\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\n\t} catch (error) {\n\t\tconst evaluateRoll = roll(compareResult.dice) as Resultat | undefined;\n\t\tif (evaluateRoll)\n\t\t\treturn `${validSign} ${diceAll}: ${evaluateRoll.result.split(\":\").splice(1).join(\":\")}`;\n\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\n\t}\n}\n\nfunction compareSignFormule(\n\ttoRoll: string,\n\tcompareRegex: RegExpMatchArray,\n\telement: string,\n\tdiceResult: Resultat\n) {\n\tlet results = \"\";\n\tconst compareResult = getCompare(toRoll, compareRegex);\n\tconst toCompare = `${compareResult.dice}${compareResult.compare?.sign}${compareResult.compare?.value}`;\n\tlet res: unknown;\n\ttry {\n\t\tres = evaluate(toCompare);\n\t} catch (error) {\n\t\tres = roll(toCompare);\n\t}\n\tif (typeof res === \"boolean\") {\n\t\tresults = replaceInFormula(element, diceResult, compareResult, res);\n\t} else if (res instanceof Object) {\n\t\tconst result = res as Resultat;\n\t\tif (result.compare) {\n\t\t\tconst toEvaluate = evaluate(\n\t\t\t\t`${result.total}${result.compare.sign}${result.compare.value}`\n\t\t\t);\n\t\t\tconst sign = toEvaluate ? \"✓\" : \"✕\";\n\t\t\tconst invertedSign = toEvaluate\n\t\t\t\t? result.compare.sign\n\t\t\t\t: inverseSign(result.compare.sign);\n\t\t\tconst dice = element\n\t\t\t\t.replace(\"µ\", `[${diceResult.dice.replace(COMMENT_REGEX, \"\")}]`)\n\t\t\t\t.trim();\n\t\t\tresults = `${sign} ${dice}: ${result.result.split(\":\").splice(1).join(\":\").trim()}${invertedSign}${result.compare.value}`;\n\t\t}\n\t}\n\treturn { dice: compareResult.dice, results };\n}\n\nexport function multipleFunction(dice: string): Resultat | undefined {\n\tconst results = [];\n\tconst split = dice.split(\";\");\n\tconst diceResult = roll(split[0]);\n\tif (!diceResult || !diceResult.total) return undefined;\n\tresults.push(`${diceResult.result}`);\n\n\tlet total = diceResult.total;\n\tlet comments = diceResult.comment ?? \"\";\n\tif (!total) return diceResult;\n\tfor (let element of split.slice(1)) {\n\t\tif (!element.includes(\"µ\")) {\n\t\t\tconst result = roll(element);\n\t\t\tif (!result) continue;\n\t\t\tresults.push(result.result);\n\t\t\tcontinue;\n\t\t}\n\t\t//remove comments & keep it\n\t\tconst commentMatch = element.match(COMMENT_REGEX);\n\t\telement = element.replace(COMMENT_REGEX, \"\");\n\t\tconst comment = commentMatch ? commentMatch[2] : undefined;\n\t\tif (comment) comments += ` ${comment}`;\n\t\tlet toRoll = element.replace(\"µ\", `${diceResult.total}`);\n\t\tconst compareRegex = toRoll.match(SIGN_REGEX_SPACE);\n\t\tif (compareRegex) {\n\t\t\tconst compareResult = compareSignFormule(toRoll, compareRegex, element, diceResult);\n\t\t\ttoRoll = compareResult.dice;\n\t\t\tresults.push(compareResult.results);\n\t\t} else {\n\t\t\tconst formule = element.replace(\"µ\", `[${diceResult.total}]`).trim();\n\t\t\tconst diceAll = element.replace(\n\t\t\t\t\"µ\",\n\t\t\t\t`[${diceResult.dice.replace(COMMENT_REGEX, \"\")}]`\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tconst evaluated = evaluate(toRoll);\n\t\t\t\tresults.push(`◈ ${diceAll}: ${formule} = ${evaluated}`);\n\t\t\t\ttotal += Number.parseInt(evaluated, 10);\n\t\t\t} catch (error) {\n\t\t\t\tconst evaluated = roll(toRoll);\n\t\t\t\tif (evaluated)\n\t\t\t\t\tresults.push(`◈ ${diceAll}: ${evaluated.result.split(\":\").slice(1).join(\":\")}`);\n\t\t\t\telse results.push(`◈ ${diceAll}:${formule} = ${evaluated}`);\n\t\t\t\ttotal += evaluated?.total ?? 0;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tdice: split[0],\n\t\tresult: results.join(\";\"),\n\t\tcomment: comments,\n\t\tcompare: diceResult.compare,\n\t\tmodifier: diceResult.modifier,\n\t\ttotal,\n\t};\n}\n","export class DiceTypeError extends Error {\n\tpublic readonly dice: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(dice: string, cause?: string, method?: unknown) {\n\t\tsuper(dice);\n\t\tthis.name = \"Invalid_Dice_Type\";\n\t\tthis.dice = dice;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class FormulaError extends Error {\n\tpublic readonly formula: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(formula: string, cause?: string, method?: unknown) {\n\t\tsuper(formula);\n\t\tthis.name = \"Invalid_Formula\";\n\t\tthis.formula = formula;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class MaxGreater extends Error {\n\tpublic readonly name: string;\n\tpublic readonly value: number;\n\tpublic readonly max: number;\n\n\tconstructor(value: number, max: number) {\n\t\tsuper(value.toString());\n\t\tthis.name = \"Max_Greater\";\n\t\tthis.value = value;\n\t\tthis.max = max;\n\t}\n}\n\nexport class EmptyObjectError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Empty_Object\";\n\t}\n}\n\nexport class TooManyDice extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Dice\";\n\t}\n}\n\nexport class TooManyStats extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Stats\";\n\t}\n}\n\nexport class NoStatisticsError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"No_Statistics\";\n\t}\n}\n","import { evaluate } from \"mathjs\";\nimport removeAccents from \"remove-accents\";\nimport { FormulaError } from \"./errors\";\n\n/**\n * Escape regex string\n * @param string {string}\n */\nexport function escapeRegex(string: string) {\n\treturn string.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Replace the stat name by their value using stat and after evaluate any formula using `replaceFormulaInDice`\n * @param originalDice {dice}\n * @param stats {[name: string]: number}\n */\nexport function generateStatsDice(\n\toriginalDice: string,\n\tstats?: { [name: string]: number }\n) {\n\tlet dice = originalDice;\n\tif (stats && Object.keys(stats).length > 0) {\n\t\t//damage field support adding statistic, like : 1d6 + strength\n\t\t//check if the value contains a statistic & calculate if it's okay\n\t\t//the dice will be converted before roll\n\t\tconst allStats = Object.keys(stats);\n\t\tfor (const stat of allStats) {\n\t\t\tconst regex = new RegExp(escapeRegex(removeAccents(stat)), \"gi\");\n\t\t\tif (dice.match(regex)) {\n\t\t\t\tconst statValue = stats[stat];\n\t\t\t\tdice = dice.replace(regex, statValue.toString());\n\t\t\t}\n\t\t}\n\t}\n\treturn replaceFormulaInDice(dice);\n}\n\n/**\n * Replace the {{}} in the dice string and evaluate the interior if any\n * @param dice {string}\n */\nexport function replaceFormulaInDice(dice: string) {\n\tconst formula = /(?<formula>\\{{2}(.+?)\\}{2})/gim;\n\tconst formulaMatch = formula.exec(dice);\n\tif (formulaMatch?.groups?.formula) {\n\t\tconst formula = formulaMatch.groups.formula.replaceAll(\"{{\", \"\").replaceAll(\"}}\", \"\");\n\t\ttry {\n\t\t\tconst result = evaluate(formula);\n\t\t\treturn cleanedDice(dice.replace(formulaMatch.groups.formula, result.toString()));\n\t\t} catch (error) {\n\t\t\tthrow new FormulaError(formulaMatch.groups.formula, \"replaceFormulaInDice\", error);\n\t\t}\n\t}\n\treturn cleanedDice(dice);\n}\n\n/**\n * Replace the ++ +- -- by their proper value:\n * - `++` = `+`\n * - `+-` = `-`\n * - `--` = `+`\n * @param dice {string}\n */\nexport function cleanedDice(dice: string) {\n\treturn dice.replaceAll(\"+-\", \"-\").replaceAll(\"--\", \"+\").replaceAll(\"++\", \"+\");\n}\n","/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { evaluate } from \"mathjs\";\nimport { Random } from \"random-js\";\nimport removeAccents from \"remove-accents\";\n\nimport type { Statistic, StatisticalTemplate } from \".\";\nimport { roll } from \"./dice\";\nimport { escapeRegex, replaceFormulaInDice } from \"./utils\";\nimport {\n\tDiceTypeError,\n\tEmptyObjectError,\n\tFormulaError,\n\tMaxGreater,\n\tNoStatisticsError,\n\tTooManyDice,\n\tTooManyStats,\n} from \"./errors\";\n\n/**\n * Verify if the provided dice work with random value\n * @param testDice {string}\n * @param stats {[name: string]: number}\n */\nexport function evalStatsDice(testDice: string, stats?: { [name: string]: number }) {\n\tlet dice = testDice;\n\tif (stats && Object.keys(stats).length > 0) {\n\t\tconst allStats = Object.keys(stats);\n\t\tfor (const stat of allStats) {\n\t\t\tconst regex = new RegExp(escapeRegex(removeAccents(stat)), \"gi\");\n\t\t\tif (testDice.match(regex)) {\n\t\t\t\tconst statValue = stats[stat];\n\t\t\t\tdice = testDice.replace(regex, statValue.toString());\n\t\t\t}\n\t\t}\n\t}\n\ttry {\n\t\tif (!roll(replaceFormulaInDice(dice)))\n\t\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", \"no roll result\");\n\t\treturn testDice;\n\t} catch (error) {\n\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", error);\n\t}\n}\n\n/**\n * Generate a random dice and remove the formula (+ evaluate it)\n * Used for diceDamage only\n * @param value {string}\n * @param template {StatisticalTemplate}\n * @returns\n */\nexport function diceRandomParse(value: string, template: StatisticalTemplate) {\n\tif (!template.statistics) return value;\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\tvalue = removeAccents(value);\n\tconst allStats = Object.keys(template.statistics).map((stat) =>\n\t\tremoveAccents(stat).toLowerCase()\n\t);\n\tlet newDice = value;\n\tfor (const stat of allStats) {\n\t\tconst regex = new RegExp(escapeRegex(stat), \"gi\");\n\t\tif (value.match(regex)) {\n\t\t\tlet max: undefined | number = undefined;\n\t\t\tlet min: undefined | number = undefined;\n\t\t\tconst stats = template.statistics?.[stat];\n\t\t\tif (stats) {\n\t\t\t\tmax = template.statistics[removeAccents(stat).toLowerCase()].max;\n\t\t\t\tmin = template.statistics[removeAccents(stat).toLowerCase()].min;\n\t\t\t}\n\t\t\tconst total = template.total || 100;\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\n\t\t\tnewDice = value.replace(regex, randomStatValue.toString());\n\t\t}\n\t}\n\treturn replaceFormulaInDice(newDice);\n}\n\n/**\n * Same as damageDice but for DiceType\n * @param dice {string}\n * @param template {StatisticalTemplate}\n */\nexport function diceTypeRandomParse(dice: string, template: StatisticalTemplate) {\n\tif (!template.statistics) return dice;\n\tconst firstStatNotCombinaison = Object.keys(template.statistics).find(\n\t\t(stat) => !template.statistics?.[stat].combinaison\n\t);\n\tif (!firstStatNotCombinaison) return dice;\n\tconst stats = template.statistics[firstStatNotCombinaison];\n\tconst { min, max } = stats;\n\tconst total = template.total || 100;\n\tconst randomStatValue = generateRandomStat(total, max, min);\n\treturn replaceFormulaInDice(dice.replace(\"$\", randomStatValue.toString()));\n}\n\n/**\n * Random the combinaison and evaluate it to check if everything is valid\n * @param combinaison {[name: string]: string}\n * @param stats {[name: string]: string|number}\n */\nexport function evalCombinaison(\n\tcombinaison: { [name: string]: string },\n\tstats: { [name: string]: string | number }\n) {\n\tconst newStats: { [name: string]: number } = {};\n\tfor (const [stat, combin] of Object.entries(combinaison)) {\n\t\t//replace the stats in formula\n\t\tlet formula = removeAccents(combin);\n\t\tfor (const [statName, value] of Object.entries(stats)) {\n\t\t\tconst regex = new RegExp(removeAccents(statName), \"gi\");\n\t\t\tformula = formula.replace(regex, value.toString());\n\t\t}\n\t\ttry {\n\t\t\tconst result = evaluate(formula);\n\t\t\tnewStats[stat] = result;\n\t\t} catch (error) {\n\t\t\tthrow new FormulaError(stat, \"evalCombinaison\", error);\n\t\t}\n\t}\n\treturn newStats;\n}\n\n/**\n * Evaluate one selected combinaison\n * @param combinaison {string}\n * @param stats {[name: string]: string|number}\n */\nexport function evalOneCombinaison(\n\tcombinaison: string,\n\tstats: { [name: string]: string | number }\n) {\n\tlet formula = removeAccents(combinaison);\n\tfor (const [statName, value] of Object.entries(stats)) {\n\t\tconst regex = new RegExp(removeAccents(statName), \"gi\");\n\t\tformula = formula.replace(regex, value.toString());\n\t}\n\ttry {\n\t\treturn evaluate(formula);\n\t} catch (error) {\n\t\tthrow new FormulaError(combinaison, \"evalOneCombinaison\", error);\n\t}\n}\n\n/**\n * Parse the provided JSON and verify each field to check if everything could work when rolling\n * @param {any} template\n * @returns {StatisticalTemplate}\n */\n//biome-ignore lint/suspicious/noExplicitAny: I need to use any to allow any type\nexport function verifyTemplateValue(template: any): StatisticalTemplate {\n\tconst statistiqueTemplate: StatisticalTemplate = {\n\t\tdiceType: \"\",\n\t\tstatistics: {} as Statistic,\n\t};\n\tif (!template.statistics) statistiqueTemplate.statistics = undefined;\n\telse if (template.statistics && Object.keys(template.statistics).length > 0) {\n\t\tif (Object.keys(template.statistics).length > 25) throw new TooManyStats();\n\t\tfor (const [key, value] of Object.entries(template.statistics)) {\n\t\t\tconst dataValue = value as { max?: number; min?: number; combinaison?: string };\n\t\t\tif (dataValue.max && dataValue.min && dataValue.max <= dataValue.min)\n\t\t\t\tthrow new MaxGreater(dataValue.min, dataValue.max);\n\t\t\tif (dataValue.max && dataValue.max <= 0) dataValue.max = undefined;\n\t\t\tif (dataValue.min && dataValue.min <= 0) dataValue.min = undefined;\n\t\t\tlet formula = dataValue.combinaison\n\t\t\t\t? removeAccents(dataValue.combinaison).toLowerCase()\n\t\t\t\t: undefined;\n\t\t\tformula = formula && formula.trim().length > 0 ? formula : undefined;\n\t\t\tif (!statistiqueTemplate.statistics) {\n\t\t\t\tstatistiqueTemplate.statistics = {} as Statistic;\n\t\t\t}\n\t\t\tstatistiqueTemplate.statistics[key] = {\n\t\t\t\tmax: dataValue.max,\n\t\t\t\tmin: dataValue.min,\n\t\t\t\tcombinaison: formula || undefined,\n\t\t\t};\n\t\t}\n\t}\n\tif (template.diceType) {\n\t\ttry {\n\t\t\tstatistiqueTemplate.diceType = template.diceType;\n\t\t\tconst cleanedDice = diceTypeRandomParse(template.diceType, statistiqueTemplate);\n\t\t\tconst rolled = roll(cleanedDice);\n\t\t\tif (!rolled)\n\t\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\n\t\t} catch (e) {\n\t\t\tthrow new Error((e as Error).message);\n\t\t}\n\t}\n\n\tif (template.critical && Object.keys(template.critical).length > 0) {\n\t\tstatistiqueTemplate.critical = {\n\t\t\tfailure: template.critical.failure ?? undefined,\n\t\t\tsuccess: template.critical.success ?? undefined,\n\t\t};\n\t}\n\tif (template.total) {\n\t\tif (template.total <= 0) template.total = undefined;\n\t\tstatistiqueTemplate.total = template.total;\n\t}\n\tif (template.charName) statistiqueTemplate.charName = template.charName;\n\tif (template.damage) statistiqueTemplate.damage = template.damage;\n\ttry {\n\t\ttestDiceRegistered(statistiqueTemplate);\n\t\ttestStatCombinaison(statistiqueTemplate);\n\t} catch (error) {\n\t\tthrow new Error((error as Error).message);\n\t}\n\treturn statistiqueTemplate;\n}\n\n/**\n * Test each damage roll from the template.damage\n * @param {StatisticalTemplate} template\n */\nexport function testDiceRegistered(template: StatisticalTemplate) {\n\tif (!template.damage) return;\n\tif (Object.keys(template.damage).length === 0) throw new EmptyObjectError();\n\tif (Object.keys(template.damage).length > 25) throw new TooManyDice();\n\tfor (const [name, dice] of Object.entries(template.damage)) {\n\t\tif (!dice) continue;\n\t\tconst randomDiceParsed = diceRandomParse(dice, template);\n\t\ttry {\n\t\t\tconst rolled = roll(randomDiceParsed);\n\t\t\tif (!rolled) throw new DiceTypeError(name, \"testDiceRegistered\", \"no roll result\");\n\t\t} catch (error) {\n\t\t\tthrow new DiceTypeError(name, \"testDiceRegistered\", error);\n\t\t}\n\t}\n}\n\n/**\n * Test all combinaison with generated random value\n * @param {StatisticalTemplate} template\n */\nexport function testStatCombinaison(template: StatisticalTemplate) {\n\tif (!template.statistics) return;\n\tconst onlyCombinaisonStats = Object.fromEntries(\n\t\tObject.entries(template.statistics).filter(\n\t\t\t([_, value]) => value.combinaison !== undefined\n\t\t)\n\t);\n\tconst allOtherStats = Object.fromEntries(\n\t\tObject.entries(template.statistics).filter(([_, value]) => !value.combinaison)\n\t);\n\tif (Object.keys(onlyCombinaisonStats).length === 0) return;\n\tconst allStats = Object.keys(template.statistics).filter(\n\t\t(stat) => !template.statistics![stat].combinaison\n\t);\n\tif (allStats.length === 0) throw new NoStatisticsError();\n\tconst error = [];\n\tfor (const [stat, value] of Object.entries(onlyCombinaisonStats)) {\n\t\tlet formula = value.combinaison as string;\n\t\tfor (const [other, data] of Object.entries(allOtherStats)) {\n\t\t\tconst { max, min } = data;\n\t\t\tconst total = template.total || 100;\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\n\t\t\tconst regex = new RegExp(other, \"gi\");\n\t\t\tformula = formula.replace(regex, randomStatValue.toString());\n\t\t}\n\t\ttry {\n\t\t\tevaluate(formula);\n\t\t} catch (e) {\n\t\t\terror.push(stat);\n\t\t}\n\t}\n\tif (error.length > 0) throw new FormulaError(error.join(\", \"), \"testStatCombinaison\");\n\treturn;\n}\n\n/**\n * Generate a random stat based on the template and the statistical min and max\n * @param {number|undefined} total\n * @param {number | undefined} max\n * @param {number | undefined} min\n * @returns\n */\nexport function generateRandomStat(\n\ttotal: number | undefined = 100,\n\tmax?: number,\n\tmin?: number\n) {\n\tlet randomStatValue = total + 1;\n\twhile (randomStatValue >= total) {\n\t\tconst random = new Random();\n\t\tif (max && min) randomStatValue = random.integer(min, max);\n\t\telse if (max) randomStatValue = random.integer(0, max);\n\t\telse if (min) randomStatValue = random.integer(min, total);\n\t\telse randomStatValue = random.integer(0, total);\n\t}\n\treturn randomStatValue;\n}\n"],"mappings":";AACA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;;;ACFlB,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,MAAc,OAAgB,QAAkB;AAC3D,UAAM,IAAI;AACV,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EACf;AACD;AAEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,SAAiB,OAAgB,QAAkB;AAC9D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EACf;AACD;AAEO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,OAAe,KAAa;AACvC,UAAM,MAAM,SAAS,CAAC;AACtB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,MAAM;AAAA,EACZ;AACD;AAEO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC3B;AAAA,EAEhB,cAAc;AACb,UAAM;AACN,SAAK,OAAO;AAAA,EACb;AACD;AAEO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACtB;AAAA,EAEhB,cAAc;AACb,UAAM;AACN,SAAK,OAAO;AAAA,EACb;AACD;AAEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACvB;AAAA,EAEhB,cAAc;AACb,UAAM;AACN,SAAK,OAAO;AAAA,EACb;AACD;AAEO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC5B;AAAA,EAEhB,cAAc;AACb,UAAM;AACN,SAAK,OAAO;AAAA,EACb;AACD;;;ADpEO,IAAM,gBAAgB;AAC7B,IAAM,aAAa;AACnB,IAA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AASO,SAAS,mBACf,QAA4B,KAC5B,KACA,KACC;AACD,MAAI,kBAAkB,QAAQ;AAC9B,SAAO,mBAAmB,OAAO;AAChC,UAAM,SAAS,IAAI,OAAO;AAC1B,QAAI,OAAO;AAAK,wBAAkB,OAAO,QAAQ,KAAK,GAAG;AAAA,aAChD;AAAK,wBAAkB,OAAO,QAAQ,GAAG,GAAG;AAAA,aAC5C;AAAK,wBAAkB,OAAO,QAAQ,KAAK,KAAK;AAAA;AACpD,wBAAkB,OAAO,QAAQ,GAAG,KAAK;AAAA,EAC/C;AACA,SAAO;AACR;","names":["roller","evaluateRoll","evaluate","formula","evaluate","evaluate","removeAccents","removeAccents","evaluate","cleanedDice"]}
1
+ {"version":3,"sources":["../src/dice.ts","../src/errors.ts","../src/interfaces/constant.ts","../src/utils.ts","../src/verify_template.ts"],"sourcesContent":["/* eslint-disable no-useless-escape */\r\nimport { DiceRoller } from \"@dice-roller/rpg-dice-roller\";\r\nimport { evaluate } from \"mathjs\";\r\n\r\nimport type { Compare, Modifier, Resultat, Sign } from \".\";\r\nimport { DiceTypeError } from \"./errors\";\r\nimport {\r\n\tCOMMENT_REGEX,\r\n\tSIGN_REGEX,\r\n\tSIGN_REGEX_SPACE,\r\n\tSYMBOL_DICE,\r\n} from \"./interfaces/constant\";\r\n\r\nfunction getCompare(\r\n\tdice: string,\r\n\tcompareRegex: RegExpMatchArray\r\n): { dice: string; compare: Compare | undefined } {\r\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\r\n\tdice = dice.replace(SIGN_REGEX_SPACE, \"\");\r\n\tlet compare: Compare;\r\n\tconst calc = compareRegex[1];\r\n\tconst sign = calc.match(/[+-\\/*^]/)?.[0];\r\n\tconst compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];\r\n\tif (sign) {\r\n\t\tconst toCalc = calc.replace(SIGN_REGEX, \"\").replace(/\\s/g, \"\").replace(/;(.*)/, \"\");\r\n\t\tconst total = evaluate(toCalc);\r\n\t\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\r\n\t\tdice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: total,\r\n\t\t};\r\n\t} else\r\n\t\tcompare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: Number.parseInt(calc, 10),\r\n\t\t};\r\n\treturn { dice, compare };\r\n}\r\n\r\nfunction getModifier(dice: string) {\r\n\tconst modifier = dice.matchAll(/(\\+|-|%|\\/|\\^|\\*|\\*{2})(\\d+)/gi);\r\n\tlet modificator: Modifier | undefined;\r\n\tfor (const mod of modifier) {\r\n\t\t//calculate the modifier if multiple\r\n\t\tif (modificator) {\r\n\t\t\tconst sign = modificator.sign;\r\n\t\t\tlet value = modificator.value;\r\n\t\t\tif (sign) value = calculator(sign, value, Number.parseInt(mod[2], 10));\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue,\r\n\t\t\t};\r\n\t\t} else {\r\n\t\t\tmodificator = {\r\n\t\t\t\tsign: mod[1] as Sign,\r\n\t\t\t\tvalue: Number.parseInt(mod[2], 10),\r\n\t\t\t};\r\n\t\t}\r\n\t}\r\n\treturn modificator;\r\n}\r\n\r\n/**\r\n * Parse the string provided and turn it as a readable dice for dice parser\r\n * @param dice {string}\r\n */\r\nexport function roll(dice: string): Resultat | undefined {\r\n\t//parse dice string\r\n\tif (!dice.includes(\"d\")) return undefined;\r\n\tconst compareRegex = dice.match(SIGN_REGEX_SPACE);\r\n\tlet compare: Compare | undefined;\r\n\tif (dice.includes(\";\") && dice.includes(\"&\")) return sharedRolls(dice);\r\n\tif (compareRegex) {\r\n\t\tconst compareResult = getCompare(dice, compareRegex);\r\n\t\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\r\n\t\tdice = compareResult.dice;\r\n\t\tcompare = compareResult.compare;\r\n\t}\r\n\tconst modificator = getModifier(dice);\r\n\r\n\tif (dice.match(/\\d+?#(.*)/)) {\r\n\t\tconst diceArray = dice.split(\"#\");\r\n\t\tconst numberOfDice = Number.parseInt(diceArray[0], 10);\r\n\t\tconst diceToRoll = diceArray[1].replace(COMMENT_REGEX, \"\");\r\n\t\tconst commentsMatch = diceArray[1].match(COMMENT_REGEX);\r\n\t\tconst comments = commentsMatch ? commentsMatch[2] : undefined;\r\n\t\tconst roller = new DiceRoller();\r\n\t\t//remove comments if any\r\n\t\tfor (let i = 0; i < numberOfDice; i++) {\r\n\t\t\ttry {\r\n\t\t\t\troller.roll(diceToRoll);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tthrow new DiceTypeError(diceToRoll, \"roll\", error);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tdice: diceToRoll,\r\n\t\t\tresult: roller.output,\r\n\t\t\tcomment: comments,\r\n\t\t\tcompare: compare ? compare : undefined,\r\n\t\t\tmodifier: modificator,\r\n\t\t\ttotal: roller.total,\r\n\t\t};\r\n\t}\r\n\tconst roller = new DiceRoller();\r\n\tconst diceWithoutComment = dice.replace(COMMENT_REGEX, \"\");\r\n\ttry {\r\n\t\troller.roll(diceWithoutComment);\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(diceWithoutComment, \"roll\", error);\r\n\t}\r\n\tconst commentMatch = dice.match(COMMENT_REGEX);\r\n\tconst comment = commentMatch ? commentMatch[2] : undefined;\r\n\treturn {\r\n\t\tdice,\r\n\t\tresult: roller.output,\r\n\t\tcomment,\r\n\t\tcompare: compare ? compare : undefined,\r\n\t\tmodifier: modificator,\r\n\t\ttotal: roller.total,\r\n\t};\r\n}\r\n/**\r\n * Evaluate a formula and replace \"^\" by \"**\" if any\r\n * @param {Sign} sign\r\n * @param {number} value\r\n * @param {number} total\r\n * @returns\r\n */\r\nexport function calculator(sign: Sign, value: number, total: number): number {\r\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\r\n\tif (sign === \"^\") sign = \"**\";\r\n\treturn evaluate(`${total} ${sign} ${value}`);\r\n}\r\n\r\nfunction inverseSign(\r\n\tsign: \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\"\r\n): \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\" {\r\n\tswitch (sign) {\r\n\t\tcase \"<\":\r\n\t\t\treturn \">\";\r\n\t\tcase \">\":\r\n\t\t\treturn \"<\";\r\n\t\tcase \"<=\":\r\n\t\t\treturn \">=\";\r\n\t\tcase \">=\":\r\n\t\t\treturn \"<=\";\r\n\t\tcase \"=\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"==\":\r\n\t\t\treturn \"!=\";\r\n\t\tcase \"!=\":\r\n\t\t\treturn \"==\";\r\n\t}\r\n}\r\n\r\nfunction replaceInFormula(\r\n\telement: string,\r\n\tdiceResult: Resultat,\r\n\tcompareResult: { dice: string; compare: Compare | undefined },\r\n\tres: boolean\r\n) {\r\n\tconst { formule, diceAll } = replaceText(\r\n\t\telement,\r\n\t\tdiceResult.total ?? 0,\r\n\t\tdiceResult.dice\r\n\t);\r\n\tconst validSign = res ? \"✓\" : \"✕\";\r\n\tconst invertedSign = res\r\n\t\t? compareResult.compare!.sign\r\n\t\t: inverseSign(compareResult.compare!.sign);\r\n\tlet evaluateRoll: unknown;\r\n\ttry {\r\n\t\tevaluateRoll = evaluate(compareResult.dice);\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t} catch (error) {\r\n\t\tconst evaluateRoll = roll(compareResult.dice) as Resultat | undefined;\r\n\t\tif (evaluateRoll)\r\n\t\t\treturn `${validSign} ${diceAll}: ${evaluateRoll.result.split(\":\").splice(1).join(\":\")}`;\r\n\r\n\t\treturn `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;\r\n\t}\r\n}\r\n\r\nfunction compareSignFormule(\r\n\ttoRoll: string,\r\n\tcompareRegex: RegExpMatchArray,\r\n\telement: string,\r\n\tdiceResult: Resultat\r\n) {\r\n\tlet results = \"\";\r\n\tconst compareResult = getCompare(toRoll, compareRegex);\r\n\tconst toCompare = `${compareResult.dice}${compareResult.compare?.sign}${compareResult.compare?.value}`;\r\n\tlet res: unknown;\r\n\ttry {\r\n\t\tres = evaluate(toCompare);\r\n\t} catch (error) {\r\n\t\tres = roll(toCompare);\r\n\t}\r\n\tif (typeof res === \"boolean\") {\r\n\t\tresults = replaceInFormula(element, diceResult, compareResult, res);\r\n\t} else if (res instanceof Object) {\r\n\t\tconst diceResult = res as Resultat;\r\n\t\tif (diceResult.compare) {\r\n\t\t\tconst toEvaluate = evaluate(\r\n\t\t\t\t`${diceResult.total}${diceResult.compare.sign}${diceResult.compare.value}`\r\n\t\t\t);\r\n\t\t\tconst sign = toEvaluate ? \"✓\" : \"✕\";\r\n\t\t\tconst invertedSign = toEvaluate\r\n\t\t\t\t? diceResult.compare.sign\r\n\t\t\t\t: inverseSign(diceResult.compare.sign);\r\n\t\t\tconst dice = replaceText(element, 0, diceResult.dice).diceAll;\r\n\r\n\t\t\tresults = `${sign} ${dice}: ${diceResult.result.split(\":\").splice(1).join(\":\").trim()}${invertedSign}${diceResult.compare.value}`;\r\n\t\t}\r\n\t}\r\n\treturn { dice: compareResult.dice, results };\r\n}\r\n\r\nfunction replaceText(element: string, total: number, dice: string) {\r\n\treturn {\r\n\t\tformule: element.replace(SYMBOL_DICE, `[${total}]`).trim(),\r\n\t\tdiceAll: element.replace(SYMBOL_DICE, `[${dice.replace(COMMENT_REGEX, \"\")}]`).trim(),\r\n\t};\r\n}\r\n\r\nfunction sharedRolls(dice: string): Resultat | undefined {\r\n\t/* bulk roll are not allowed in shared rolls */\r\n\tif (dice.includes(\"#\"))\r\n\t\tthrow new DiceTypeError(\r\n\t\t\tdice,\r\n\t\t\t\"noBulkRoll\",\r\n\t\t\t\"bulk roll are not allowed in shared rolls\"\r\n\t\t);\r\n\tconst results = [];\r\n\tconst split = dice.split(\";\");\r\n\tconst diceResult = roll(split[0]);\r\n\tif (!diceResult || !diceResult.total) return undefined;\r\n\tresults.push(`${diceResult.result}`);\r\n\r\n\tlet total = diceResult.total;\r\n\tlet comments = diceResult.comment ?? \"\";\r\n\tif (!total) return diceResult;\r\n\tfor (let element of split.slice(1)) {\r\n\t\tif (!element.includes(SYMBOL_DICE)) {\r\n\t\t\tconst result = roll(element);\r\n\t\t\tif (!result) continue;\r\n\t\t\tresults.push(result.result);\r\n\t\t\tcontinue;\r\n\t\t}\r\n\t\t//remove comments & keep it\r\n\t\tconst commentMatch = element.match(COMMENT_REGEX);\r\n\t\telement = element.replace(COMMENT_REGEX, \"\");\r\n\t\tconst comment = commentMatch ? commentMatch[2] : undefined;\r\n\t\tif (comment) comments += ` ${comment}`;\r\n\t\tlet toRoll = element.replace(SYMBOL_DICE, `${diceResult.total}`);\r\n\t\tconst compareRegex = toRoll.match(SIGN_REGEX_SPACE);\r\n\t\tif (compareRegex) {\r\n\t\t\tconst compareResult = compareSignFormule(toRoll, compareRegex, element, diceResult);\r\n\t\t\ttoRoll = compareResult.dice;\r\n\t\t\tresults.push(compareResult.results);\r\n\t\t} else {\r\n\t\t\tconst { formule, diceAll } = replaceText(\r\n\t\t\t\telement,\r\n\t\t\t\tdiceResult.total,\r\n\t\t\t\tdiceResult.dice\r\n\t\t\t);\r\n\r\n\t\t\ttry {\r\n\t\t\t\tconst evaluated = evaluate(toRoll);\r\n\t\t\t\tresults.push(`◈ ${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += Number.parseInt(evaluated, 10);\r\n\t\t\t} catch (error) {\r\n\t\t\t\tconst evaluated = roll(toRoll);\r\n\t\t\t\tif (evaluated)\r\n\t\t\t\t\tresults.push(`◈ ${diceAll}: ${evaluated.result.split(\":\").slice(1).join(\":\")}`);\r\n\t\t\t\telse results.push(`◈ ${diceAll}: ${formule} = ${evaluated}`);\r\n\t\t\t\ttotal += evaluated?.total ?? 0;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\treturn {\r\n\t\tdice: split[0],\r\n\t\tresult: results.join(\";\"),\r\n\t\tcomment: comments,\r\n\t\tcompare: diceResult.compare,\r\n\t\tmodifier: diceResult.modifier,\r\n\t\ttotal,\r\n\t};\r\n}\r\n","export class DiceTypeError extends Error {\n\tpublic readonly dice: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(dice: string, cause?: string, method?: unknown) {\n\t\tsuper(dice);\n\t\tthis.name = \"Invalid_Dice_Type\";\n\t\tthis.dice = dice;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class FormulaError extends Error {\n\tpublic readonly formula: string;\n\tpublic readonly cause: string | undefined;\n\tpublic readonly method: unknown;\n\n\tconstructor(formula: string, cause?: string, method?: unknown) {\n\t\tsuper(formula);\n\t\tthis.name = \"Invalid_Formula\";\n\t\tthis.formula = formula;\n\t\tthis.cause = cause;\n\t\tthis.method = method;\n\t}\n}\n\nexport class MaxGreater extends Error {\n\tpublic readonly name: string;\n\tpublic readonly value: number;\n\tpublic readonly max: number;\n\n\tconstructor(value: number, max: number) {\n\t\tsuper(value.toString());\n\t\tthis.name = \"Max_Greater\";\n\t\tthis.value = value;\n\t\tthis.max = max;\n\t}\n}\n\nexport class EmptyObjectError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Empty_Object\";\n\t}\n}\n\nexport class TooManyDice extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Dice\";\n\t}\n}\n\nexport class TooManyStats extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"Too_Many_Stats\";\n\t}\n}\n\nexport class NoStatisticsError extends Error {\n\tpublic readonly name: string;\n\n\tconstructor() {\n\t\tsuper();\n\t\tthis.name = \"No_Statistics\";\n\t}\n}\n","export const COMMENT_REGEX = /\\s+(#|\\/{2}|\\[|\\/\\*)(.*)/;\nexport const SIGN_REGEX = /[><=!]+/;\nexport const SIGN_REGEX_SPACE = /[><=!]+(\\S+)/;\n\nexport const SYMBOL_DICE = \"&\";\n","import { evaluate } from \"mathjs\";\nimport removeAccents from \"remove-accents\";\nimport { FormulaError } from \"./errors\";\n\n/**\n * Escape regex string\n * @param string {string}\n */\nexport function escapeRegex(string: string) {\n\treturn string.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Replace the stat name by their value using stat and after evaluate any formula using `replaceFormulaInDice`\n * @param originalDice {dice}\n * @param stats {[name: string]: number}\n */\nexport function generateStatsDice(\n\toriginalDice: string,\n\tstats?: { [name: string]: number }\n) {\n\tlet dice = originalDice;\n\tif (stats && Object.keys(stats).length > 0) {\n\t\t//damage field support adding statistic, like : 1d6 + strength\n\t\t//check if the value contains a statistic & calculate if it's okay\n\t\t//the dice will be converted before roll\n\t\tconst allStats = Object.keys(stats);\n\t\tfor (const stat of allStats) {\n\t\t\tconst regex = new RegExp(escapeRegex(removeAccents(stat)), \"gi\");\n\t\t\tif (dice.match(regex)) {\n\t\t\t\tconst statValue = stats[stat];\n\t\t\t\tdice = dice.replace(regex, statValue.toString());\n\t\t\t}\n\t\t}\n\t}\n\treturn replaceFormulaInDice(dice);\n}\n\n/**\n * Replace the {{}} in the dice string and evaluate the interior if any\n * @param dice {string}\n */\nexport function replaceFormulaInDice(dice: string) {\n\tconst formula = /(?<formula>\\{{2}(.+?)\\}{2})/gim;\n\tconst formulaMatch = formula.exec(dice);\n\tif (formulaMatch?.groups?.formula) {\n\t\tconst formula = formulaMatch.groups.formula.replaceAll(\"{{\", \"\").replaceAll(\"}}\", \"\");\n\t\ttry {\n\t\t\tconst result = evaluate(formula);\n\t\t\treturn cleanedDice(dice.replace(formulaMatch.groups.formula, result.toString()));\n\t\t} catch (error) {\n\t\t\tthrow new FormulaError(formulaMatch.groups.formula, \"replaceFormulaInDice\", error);\n\t\t}\n\t}\n\treturn cleanedDice(dice);\n}\n\n/**\n * Replace the ++ +- -- by their proper value:\n * - `++` = `+`\n * - `+-` = `-`\n * - `--` = `+`\n * @param dice {string}\n */\nexport function cleanedDice(dice: string) {\n\treturn dice.replaceAll(\"+-\", \"-\").replaceAll(\"--\", \"+\").replaceAll(\"++\", \"+\");\n}\n","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { evaluate } from \"mathjs\";\r\nimport { Random } from \"random-js\";\r\nimport \"uniformize\";\r\n\r\nimport type { Statistic, StatisticalTemplate } from \".\";\r\nimport { roll } from \"./dice\";\r\nimport {\r\n\tDiceTypeError,\r\n\tEmptyObjectError,\r\n\tFormulaError,\r\n\tMaxGreater,\r\n\tNoStatisticsError,\r\n\tTooManyDice,\r\n\tTooManyStats,\r\n} from \"./errors\";\r\nimport { escapeRegex, replaceFormulaInDice } from \"./utils\";\r\n\r\n/**\r\n * Verify if the provided dice work with random value\r\n * @param testDice {string}\r\n * @param stats {[name: string]: number}\r\n */\r\nexport function evalStatsDice(testDice: string, stats?: { [name: string]: number }) {\r\n\tlet dice = testDice;\r\n\tif (stats && Object.keys(stats).length > 0) {\r\n\t\tconst allStats = Object.keys(stats);\r\n\t\tfor (const stat of allStats) {\r\n\t\t\tconst regex = new RegExp(escapeRegex(stat.standardize()), \"gi\");\r\n\t\t\tif (testDice.match(regex)) {\r\n\t\t\t\tconst statValue = stats[stat];\r\n\t\t\t\tdice = testDice.replace(regex, statValue.toString());\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\ttry {\r\n\t\tif (!roll(replaceFormulaInDice(dice)))\r\n\t\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", \"no roll result\");\r\n\t\treturn testDice;\r\n\t} catch (error) {\r\n\t\tthrow new DiceTypeError(dice, \"evalStatsDice\", error);\r\n\t}\r\n}\r\n\r\n/**\r\n * Generate a random dice and remove the formula (+ evaluate it)\r\n * Used for diceDamage only\r\n * @param value {string}\r\n * @param template {StatisticalTemplate}\r\n * @returns\r\n */\r\nexport function diceRandomParse(value: string, template: StatisticalTemplate) {\r\n\tif (!template.statistics) return value;\r\n\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\r\n\tvalue = value.standardize();\r\n\tconst allStats = Object.keys(template.statistics).map((stat) => stat.standardize());\r\n\tlet newDice = value;\r\n\tfor (const stat of allStats) {\r\n\t\tconst regex = new RegExp(escapeRegex(stat), \"gi\");\r\n\t\tif (value.match(regex)) {\r\n\t\t\tlet max: undefined | number = undefined;\r\n\t\t\tlet min: undefined | number = undefined;\r\n\t\t\tconst stats = template.statistics?.[stat];\r\n\t\t\tif (stats) {\r\n\t\t\t\tmax = template.statistics[stat.standardize()].max;\r\n\t\t\t\tmin = template.statistics[stat.standardize()].min;\r\n\t\t\t}\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tnewDice = value.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t}\r\n\treturn replaceFormulaInDice(newDice);\r\n}\r\n\r\n/**\r\n * Same as damageDice but for DiceType\r\n * @param dice {string}\r\n * @param template {StatisticalTemplate}\r\n */\r\nexport function diceTypeRandomParse(dice: string, template: StatisticalTemplate) {\r\n\tif (!template.statistics) return dice;\r\n\tconst firstStatNotcombinaison = Object.keys(template.statistics).find(\r\n\t\t(stat) => !template.statistics?.[stat].combinaison\r\n\t);\r\n\tif (!firstStatNotcombinaison) return dice;\r\n\tconst stats = template.statistics[firstStatNotcombinaison];\r\n\tconst { min, max } = stats;\r\n\tconst total = template.total || 100;\r\n\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\treturn replaceFormulaInDice(dice.replace(\"$\", randomStatValue.toString()));\r\n}\r\n\r\n/**\r\n * Random the combinaison and evaluate it to check if everything is valid\r\n * @param combinaison {[name: string]: string}\r\n * @param stats {[name: string]: string|number}\r\n */\r\nexport function evalCombinaison(\r\n\tcombinaison: { [name: string]: string },\r\n\tstats: { [name: string]: string | number }\r\n) {\r\n\tconst newStats: { [name: string]: number } = {};\r\n\tfor (const [stat, combin] of Object.entries(combinaison)) {\r\n\t\t//replace the stats in formula\r\n\t\tlet formula = combin.standardize();\r\n\t\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\t\tformula = formula.replace(regex, value.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tnewStats[stat] = evaluate(formula);\r\n\t\t} catch (error) {\r\n\t\t\tthrow new FormulaError(stat, \"evalCombinaison\", error);\r\n\t\t}\r\n\t}\r\n\treturn newStats;\r\n}\r\n\r\n/**\r\n * Evaluate one selected combinaison\r\n * @param combinaison {string}\r\n * @param stats {[name: string]: string|number}\r\n */\r\nexport function evalOneCombinaison(\r\n\tcombinaison: string,\r\n\tstats: { [name: string]: string | number }\r\n) {\r\n\tlet formula = combinaison.standardize();\r\n\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\tconst regex = new RegExp(statName.standardize(), \"gi\");\r\n\t\tformula = formula.replace(regex, value.toString());\r\n\t}\r\n\ttry {\r\n\t\treturn evaluate(formula);\r\n\t} catch (error) {\r\n\t\tthrow new FormulaError(combinaison, \"evalOneCombinaison\", error);\r\n\t}\r\n}\r\n\r\n/**\r\n * Parse the provided JSON and verify each field to check if everything could work when rolling\r\n * @param {any} template\r\n * @returns {StatisticalTemplate}\r\n */\r\n//biome-ignore lint/suspicious/noExplicitAny: I need to use any to allow any type\r\nexport function verifyTemplateValue(template: any): StatisticalTemplate {\r\n\tconst statistiqueTemplate: StatisticalTemplate = {\r\n\t\tdiceType: \"\",\r\n\t\tstatistics: {} as Statistic,\r\n\t};\r\n\tif (!template.statistics) statistiqueTemplate.statistics = undefined;\r\n\telse if (template.statistics && Object.keys(template.statistics).length > 0) {\r\n\t\tif (Object.keys(template.statistics).length > 25) throw new TooManyStats();\r\n\t\tfor (const [key, value] of Object.entries(template.statistics)) {\r\n\t\t\tconst dataValue = value as { max?: number; min?: number; combinaison?: string };\r\n\t\t\tif (dataValue.max && dataValue.min && dataValue.max <= dataValue.min)\r\n\t\t\t\tthrow new MaxGreater(dataValue.min, dataValue.max);\r\n\t\t\tif (dataValue.max && dataValue.max <= 0) dataValue.max = undefined;\r\n\t\t\tif (dataValue.min && dataValue.min <= 0) dataValue.min = undefined;\r\n\t\t\tlet formula = dataValue.combinaison\r\n\t\t\t\t? dataValue.combinaison.standardize()\r\n\t\t\t\t: undefined;\r\n\t\t\tformula = formula && formula.trim().length > 0 ? formula : undefined;\r\n\t\t\tif (!statistiqueTemplate.statistics) {\r\n\t\t\t\tstatistiqueTemplate.statistics = {} as Statistic;\r\n\t\t\t}\r\n\t\t\tstatistiqueTemplate.statistics[key] = {\r\n\t\t\t\tmax: dataValue.max,\r\n\t\t\t\tmin: dataValue.min,\r\n\t\t\t\tcombinaison: formula || undefined,\r\n\t\t\t};\r\n\t\t}\r\n\t}\r\n\tif (template.diceType) {\r\n\t\tstatistiqueTemplate.diceType = template.diceType;\r\n\t\tconst cleanedDice = diceTypeRandomParse(template.diceType, statistiqueTemplate);\r\n\t\tconst rolled = roll(cleanedDice);\r\n\t\tif (!rolled)\r\n\t\t\tthrow new DiceTypeError(cleanedDice, \"verifyTemplateValue\", \"no roll result\");\r\n\t}\r\n\r\n\tif (template.critical && Object.keys(template.critical).length > 0) {\r\n\t\tstatistiqueTemplate.critical = {\r\n\t\t\tfailure: template.critical.failure ?? undefined,\r\n\t\t\tsuccess: template.critical.success ?? undefined,\r\n\t\t};\r\n\t}\r\n\tif (template.total) {\r\n\t\tif (template.total <= 0) template.total = undefined;\r\n\t\tstatistiqueTemplate.total = template.total;\r\n\t}\r\n\tif (template.charName) statistiqueTemplate.charName = template.charName;\r\n\tif (template.damage) statistiqueTemplate.damage = template.damage;\r\n\ttestDiceRegistered(statistiqueTemplate);\r\n\ttestStatCombinaison(statistiqueTemplate);\r\n\treturn statistiqueTemplate;\r\n}\r\n\r\n/**\r\n * Test each damage roll from the template.damage\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testDiceRegistered(template: StatisticalTemplate) {\r\n\tif (!template.damage) return;\r\n\tif (Object.keys(template.damage).length === 0) throw new EmptyObjectError();\r\n\tif (Object.keys(template.damage).length > 25) throw new TooManyDice();\r\n\tfor (const [name, dice] of Object.entries(template.damage)) {\r\n\t\tif (!dice) continue;\r\n\t\tconst randomDiceParsed = diceRandomParse(dice, template);\r\n\t\ttry {\r\n\t\t\tconst rolled = roll(randomDiceParsed);\r\n\t\t\tif (!rolled) throw new DiceTypeError(name, \"testDiceRegistered\", \"no roll result\");\r\n\t\t} catch (error) {\r\n\t\t\tthrow new DiceTypeError(name, \"testDiceRegistered\", error);\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/**\r\n * Test all combinaison with generated random value\r\n * @param {StatisticalTemplate} template\r\n */\r\nexport function testStatCombinaison(template: StatisticalTemplate) {\r\n\tif (!template.statistics) return;\r\n\tconst onlycombinaisonStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(\r\n\t\t\t([_, value]) => value.combinaison !== undefined\r\n\t\t)\r\n\t);\r\n\tconst allOtherStats = Object.fromEntries(\r\n\t\tObject.entries(template.statistics).filter(([_, value]) => !value.combinaison)\r\n\t);\r\n\tif (Object.keys(onlycombinaisonStats).length === 0) return;\r\n\tconst allStats = Object.keys(template.statistics).filter(\r\n\t\t(stat) => !template.statistics![stat].combinaison\r\n\t);\r\n\tif (allStats.length === 0) throw new NoStatisticsError();\r\n\tconst error = [];\r\n\tfor (const [stat, value] of Object.entries(onlycombinaisonStats)) {\r\n\t\tlet formula = value.combinaison as string;\r\n\t\tfor (const [other, data] of Object.entries(allOtherStats)) {\r\n\t\t\tconst { max, min } = data;\r\n\t\t\tconst total = template.total || 100;\r\n\t\t\tconst randomStatValue = generateRandomStat(total, max, min);\r\n\t\t\tconst regex = new RegExp(other, \"gi\");\r\n\t\t\tformula = formula.replace(regex, randomStatValue.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tevaluate(formula);\r\n\t\t} catch (e) {\r\n\t\t\terror.push(stat);\r\n\t\t}\r\n\t}\r\n\tif (error.length > 0) throw new FormulaError(error.join(\", \"), \"testStatCombinaison\");\r\n\treturn;\r\n}\r\n\r\n/**\r\n * Generate a random stat based on the template and the statistical min and max\r\n * @param {number|undefined} total\r\n * @param {number | undefined} max\r\n * @param {number | undefined} min\r\n * @returns\r\n */\r\nexport function generateRandomStat(\r\n\ttotal: number | undefined = 100,\r\n\tmax?: number,\r\n\tmin?: number\r\n) {\r\n\tlet randomStatValue = total + 1;\r\n\twhile (randomStatValue >= total) {\r\n\t\tconst random = new Random();\r\n\t\tif (max && min) randomStatValue = random.integer(min, max);\r\n\t\telse if (max) randomStatValue = random.integer(0, max);\r\n\t\telse if (min) randomStatValue = random.integer(min, total);\r\n\t\telse randomStatValue = random.integer(0, total);\r\n\t}\r\n\treturn randomStatValue;\r\n}\r\n"],"mappings":";AACA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;;;ACFlB,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,MAAc,OAAgB,QAAkB;AAC3D,UAAM,IAAI;AACV,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EACf;AACD;AAEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,SAAiB,OAAgB,QAAkB;AAC9D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,QAAQ;AACb,SAAK,SAAS;AAAA,EACf;AACD;AAEO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACrB;AAAA,EACA;AAAA,EAC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Q,oBAAoB,GAAG;AACjE,QAAI,UAAU,MAAM;AACpB,eAAW,CAAC,OAAO,IAAI,KAAK,OAAO,QAAQ,aAAa,GAAG;AAC1D,YAAM,EAAE,KAAK,IAAI,IAAI;AACrB,YAAM,QAAQ,SAAS,SAAS;AAChC,YAAM,kBAAkB,mBAAmB,OAAO,KAAK,GAAG;AAC1D,YAAM,QAAQ,IAAI,OAAO,OAAO,IAAI;AACpC,gBAAU,QAAQ,QAAQ,OAAO,gBAAgB,SAAS,CAAC;AAAA,IAC5D;AACA,QAAI;AACH,MAAAD,UAAS,OAAO;AAAA,IACjB,SAAS,GAAG;AACX,YAAM,KAAK,IAAI;AAAA,IAChB;AAAA,EACD;AACA,MAAI,MAAM,SAAS;AAAG,UAAM,IAAI,aAAa,MAAM,KAAK,IAAI,GAAG,qBAAqB;AACpF;AACD;AASO,SAAS,mBACf,QAA4B,KAC5B,KACA,KACC;AACD,MAAI,kBAAkB,QAAQ;AAC9B,SAAO,mBAAmB,OAAO;AAChC,UAAM,SAAS,IAAI,OAAO;AAC1B,QAAI,OAAO;AAAK,wBAAkB,OAAO,QAAQ,KAAK,GAAG;AAAA,aAChD;AAAK,wBAAkB,OAAO,QAAQ,GAAG,GAAG;AAAA,aAC5C;AAAK,wBAAkB,OAAO,QAAQ,KAAK,KAAK;AAAA;AACpD,wBAAkB,OAAO,QAAQ,GAAG,KAAK;AAAA,EAC/C;AACA,SAAO;AACR;","names":["roller","evaluateRoll","diceResult","evaluate","formula","evaluate","evaluate","evaluate","cleanedDice"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dicelette/core",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "Core library for the Dicelette Discord bot",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,6 +29,7 @@
29
29
  "random-js": "^2.1.0",
30
30
  "remove-accents": "^0.5.0",
31
31
  "ts-dedent": "^2.2.0",
32
+ "uniformize": "^2.1.0",
32
33
  "vite-tsconfig-paths": "^4.3.2",
33
34
  "vitest": "^1.6.0"
34
35
  },
@@ -37,7 +38,7 @@
37
38
  "commit-and-tag-version": "^12.5.0",
38
39
  "tslib": "^2.6.2",
39
40
  "tsup": "^8.0.2",
40
- "typescript": "^5.4.3"
41
+ "typescript": "^5.7.2"
41
42
  },
42
43
  "scripts": {
43
44
  "test": "vitest",