@dicelette/core 1.1.4 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -31,6 +31,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  COMMENT_REGEX: () => COMMENT_REGEX,
34
+ DiceTypeError: () => DiceTypeError,
35
+ EmptyObjectError: () => EmptyObjectError,
36
+ FormulaError: () => FormulaError,
37
+ MaxGreater: () => MaxGreater,
38
+ NoStatisticsError: () => NoStatisticsError,
39
+ TooManyDice: () => TooManyDice,
40
+ TooManyStats: () => TooManyStats,
34
41
  calculator: () => calculator,
35
42
  cleanedDice: () => cleanedDice,
36
43
  diceRandomParse: () => diceRandomParse,
@@ -52,6 +59,73 @@ module.exports = __toCommonJS(src_exports);
52
59
  // src/dice.ts
53
60
  var import_rpg_dice_roller = require("@dice-roller/rpg-dice-roller");
54
61
  var import_mathjs = require("mathjs");
62
+
63
+ // src/errors.ts
64
+ var DiceTypeError = class extends Error {
65
+ dice;
66
+ cause;
67
+ method;
68
+ constructor(dice, cause, method) {
69
+ super(dice);
70
+ this.name = "Invalid_Dice_Type";
71
+ this.dice = dice;
72
+ this.cause = cause;
73
+ this.method = method;
74
+ }
75
+ };
76
+ var FormulaError = class extends Error {
77
+ formula;
78
+ cause;
79
+ method;
80
+ constructor(formula, cause, method) {
81
+ super(formula);
82
+ this.name = "Invalid_Formula";
83
+ this.formula = formula;
84
+ this.cause = cause;
85
+ this.method = method;
86
+ }
87
+ };
88
+ var MaxGreater = class extends Error {
89
+ name;
90
+ value;
91
+ max;
92
+ constructor(value, max) {
93
+ super(value.toString());
94
+ this.name = "Max_Greater";
95
+ this.value = value;
96
+ this.max = max;
97
+ }
98
+ };
99
+ var EmptyObjectError = class extends Error {
100
+ name;
101
+ constructor() {
102
+ super();
103
+ this.name = "Empty_Object";
104
+ }
105
+ };
106
+ var TooManyDice = class extends Error {
107
+ name;
108
+ constructor() {
109
+ super();
110
+ this.name = "Too_Many_Dice";
111
+ }
112
+ };
113
+ var TooManyStats = class extends Error {
114
+ name;
115
+ constructor() {
116
+ super();
117
+ this.name = "Too_Many_Stats";
118
+ }
119
+ };
120
+ var NoStatisticsError = class extends Error {
121
+ name;
122
+ constructor() {
123
+ super();
124
+ this.name = "No_Statistics";
125
+ }
126
+ };
127
+
128
+ // src/dice.ts
55
129
  var COMMENT_REGEX = /\s+(#|\/{2}|\[|\/\*)(.*)/;
56
130
  var SIGN_REGEX = /[><=!]+/;
57
131
  var SIGN_REGEX_SPACE = /[><=!]+(\S+)/;
@@ -76,7 +150,7 @@ function roll(dice) {
76
150
  } else
77
151
  compare = {
78
152
  sign: compareSign,
79
- value: parseInt(calc, 10)
153
+ value: Number.parseInt(calc, 10)
80
154
  };
81
155
  }
82
156
  const modifier = dice.matchAll(/(\+|\-|%|\/|\^|\*|\*{2})(\d+)/gi);
@@ -86,7 +160,7 @@ function roll(dice) {
86
160
  const sign = modificator.sign;
87
161
  let value = modificator.value;
88
162
  if (sign)
89
- value = calculator(sign, value, parseInt(mod[2], 10));
163
+ value = calculator(sign, value, Number.parseInt(mod[2], 10));
90
164
  modificator = {
91
165
  sign: mod[1],
92
166
  value
@@ -94,13 +168,13 @@ function roll(dice) {
94
168
  } else {
95
169
  modificator = {
96
170
  sign: mod[1],
97
- value: parseInt(mod[2], 10)
171
+ value: Number.parseInt(mod[2], 10)
98
172
  };
99
173
  }
100
174
  }
101
175
  if (dice.match(/\d+?#(.*)/)) {
102
176
  const diceArray = dice.split("#");
103
- const numberOfDice = parseInt(diceArray[0], 10);
177
+ const numberOfDice = Number.parseInt(diceArray[0], 10);
104
178
  const diceToRoll = diceArray[1].replace(COMMENT_REGEX, "");
105
179
  const commentsMatch = diceArray[1].match(COMMENT_REGEX);
106
180
  const comments = commentsMatch ? commentsMatch[2] : void 0;
@@ -109,7 +183,7 @@ function roll(dice) {
109
183
  try {
110
184
  roller2.roll(diceToRoll);
111
185
  } catch (error) {
112
- throw new Error(`[error.invalidDice.withoutDice, common.space]: ${diceToRoll}`);
186
+ throw new DiceTypeError(diceToRoll, "roll", error);
113
187
  }
114
188
  }
115
189
  return {
@@ -125,7 +199,7 @@ function roll(dice) {
125
199
  try {
126
200
  roller.roll(diceWithoutComment);
127
201
  } catch (error) {
128
- throw new Error(`[error.invalidDice.withoutDice, common.space]: ${diceWithoutComment}`);
202
+ throw new DiceTypeError(diceWithoutComment, "roll", error);
129
203
  }
130
204
  const commentMatch = dice.match(COMMENT_REGEX);
131
205
  const comment = commentMatch ? commentMatch[2] : void 0;
@@ -164,7 +238,7 @@ function generateStatsDice(originalDice, stats) {
164
238
  return replaceFormulaInDice(dice);
165
239
  }
166
240
  function replaceFormulaInDice(dice) {
167
- const formula = /(?<formula>\{{2}(.+?)\}{2})/gmi;
241
+ const formula = /(?<formula>\{{2}(.+?)\}{2})/gim;
168
242
  const formulaMatch = formula.exec(dice);
169
243
  if (formulaMatch?.groups?.formula) {
170
244
  const formula2 = formulaMatch.groups.formula.replaceAll("{{", "").replaceAll("}}", "");
@@ -172,7 +246,7 @@ function replaceFormulaInDice(dice) {
172
246
  const result = (0, import_mathjs2.evaluate)(formula2);
173
247
  return cleanedDice(dice.replace(formulaMatch.groups.formula, result.toString()));
174
248
  } catch (error) {
175
- throw new Error(`[error.invalidFormula, common.space]: ${formulaMatch.groups.formula}`);
249
+ throw new FormulaError(formulaMatch.groups.formula, "replaceFormulaInDice", error);
176
250
  }
177
251
  }
178
252
  return cleanedDice(dice);
@@ -199,18 +273,19 @@ function evalStatsDice(testDice, stats) {
199
273
  }
200
274
  try {
201
275
  if (!roll(replaceFormulaInDice(dice)))
202
- throw new Error(`[error.invalidDice.withoutDice, common.space] ${dice}`);
276
+ throw new DiceTypeError(dice, "evalStatsDice", "no roll result");
203
277
  return testDice;
204
278
  } catch (error) {
205
- throw new Error(`[error.invalidDice.withoutDice, common.space]: ${testDice}
206
- ${error.message}`);
279
+ throw new DiceTypeError(dice, "evalStatsDice", error);
207
280
  }
208
281
  }
209
282
  function diceRandomParse(value, template) {
210
283
  if (!template.statistics)
211
284
  return value;
212
285
  value = (0, import_remove_accents2.default)(value);
213
- const allStats = Object.keys(template.statistics).map((stat) => (0, import_remove_accents2.default)(stat).toLowerCase());
286
+ const allStats = Object.keys(template.statistics).map(
287
+ (stat) => (0, import_remove_accents2.default)(stat).toLowerCase()
288
+ );
214
289
  let newDice = value;
215
290
  for (const stat of allStats) {
216
291
  const regex = new RegExp(escapeRegex(stat), "gi");
@@ -232,7 +307,9 @@ function diceRandomParse(value, template) {
232
307
  function diceTypeRandomParse(dice, template) {
233
308
  if (!template.statistics)
234
309
  return dice;
235
- const firstStatNotCombinaison = Object.keys(template.statistics).find((stat) => !template.statistics?.[stat].combinaison);
310
+ const firstStatNotCombinaison = Object.keys(template.statistics).find(
311
+ (stat) => !template.statistics?.[stat].combinaison
312
+ );
236
313
  if (!firstStatNotCombinaison)
237
314
  return dice;
238
315
  const stats = template.statistics[firstStatNotCombinaison];
@@ -253,7 +330,7 @@ function evalCombinaison(combinaison, stats) {
253
330
  const result = (0, import_mathjs3.evaluate)(formula);
254
331
  newStats[stat] = result;
255
332
  } catch (error) {
256
- throw new Error(`[error.invalidFormula, common.space]: ${stat}`);
333
+ throw new FormulaError(stat, "evalCombinaison", error);
257
334
  }
258
335
  }
259
336
  return newStats;
@@ -267,7 +344,7 @@ function evalOneCombinaison(combinaison, stats) {
267
344
  try {
268
345
  return (0, import_mathjs3.evaluate)(formula);
269
346
  } catch (error) {
270
- throw new Error(`[error.invalidFormula, common.space]: ${combinaison}`);
347
+ throw new FormulaError(combinaison, "evalOneCombinaison", error);
271
348
  }
272
349
  }
273
350
  function verifyTemplateValue(template) {
@@ -278,10 +355,12 @@ function verifyTemplateValue(template) {
278
355
  if (!template.statistics)
279
356
  statistiqueTemplate.statistics = void 0;
280
357
  else if (template.statistics && Object.keys(template.statistics).length > 0) {
358
+ if (Object.keys(template.statistics).length > 25)
359
+ throw new TooManyStats();
281
360
  for (const [key, value] of Object.entries(template.statistics)) {
282
361
  const dataValue = value;
283
362
  if (dataValue.max && dataValue.min && dataValue.max <= dataValue.min)
284
- throw new Error("[error.maxGreater]");
363
+ throw new MaxGreater(dataValue.min, dataValue.max);
285
364
  if (dataValue.max && dataValue.max <= 0)
286
365
  dataValue.max = void 0;
287
366
  if (dataValue.min && dataValue.min <= 0)
@@ -304,7 +383,7 @@ function verifyTemplateValue(template) {
304
383
  const cleanedDice2 = diceTypeRandomParse(template.diceType, statistiqueTemplate);
305
384
  const rolled = roll(cleanedDice2);
306
385
  if (!rolled)
307
- throw new Error("[error.invalidDice.withoutDice]");
386
+ throw new DiceTypeError(cleanedDice2, "verifyTemplateValue", "no roll result");
308
387
  } catch (e) {
309
388
  throw new Error(e.message);
310
389
  }
@@ -336,9 +415,9 @@ function testDiceRegistered(template) {
336
415
  if (!template.damage)
337
416
  return;
338
417
  if (Object.keys(template.damage).length === 0)
339
- throw new Error("[error.emptyObject]");
418
+ throw new EmptyObjectError();
340
419
  if (Object.keys(template.damage).length > 25)
341
- throw new Error("[error.tooManyDice]");
420
+ throw new TooManyDice();
342
421
  for (const [name, dice] of Object.entries(template.damage)) {
343
422
  if (!dice)
344
423
  continue;
@@ -346,22 +425,30 @@ function testDiceRegistered(template) {
346
425
  try {
347
426
  const rolled = roll(randomDiceParsed);
348
427
  if (!rolled)
349
- throw new Error(`[error.invalidDice, common.space] ${name}`);
428
+ throw new DiceTypeError(name, "testDiceRegistered", "no roll result");
350
429
  } catch (error) {
351
- throw new Error(`[error.invalidDice, common.space] ${name}`);
430
+ throw new DiceTypeError(name, "testDiceRegistered", error);
352
431
  }
353
432
  }
354
433
  }
355
434
  function testStatCombinaison(template) {
356
435
  if (!template.statistics)
357
436
  return;
358
- const onlyCombinaisonStats = Object.fromEntries(Object.entries(template.statistics).filter(([_, value]) => value.combinaison !== void 0));
359
- const allOtherStats = Object.fromEntries(Object.entries(template.statistics).filter(([_, value]) => !value.combinaison));
437
+ const onlyCombinaisonStats = Object.fromEntries(
438
+ Object.entries(template.statistics).filter(
439
+ ([_, value]) => value.combinaison !== void 0
440
+ )
441
+ );
442
+ const allOtherStats = Object.fromEntries(
443
+ Object.entries(template.statistics).filter(([_, value]) => !value.combinaison)
444
+ );
360
445
  if (Object.keys(onlyCombinaisonStats).length === 0)
361
446
  return;
362
- const allStats = Object.keys(template.statistics).filter((stat) => !template.statistics[stat].combinaison);
447
+ const allStats = Object.keys(template.statistics).filter(
448
+ (stat) => !template.statistics[stat].combinaison
449
+ );
363
450
  if (allStats.length === 0)
364
- throw new Error("[error.noStat]");
451
+ throw new NoStatisticsError();
365
452
  const error = [];
366
453
  for (const [stat, value] of Object.entries(onlyCombinaisonStats)) {
367
454
  let formula = value.combinaison;
@@ -379,7 +466,7 @@ function testStatCombinaison(template) {
379
466
  }
380
467
  }
381
468
  if (error.length > 0)
382
- throw new Error(`[error.invalidFormula, common.space] ${error.join(", ")}`);
469
+ throw new FormulaError(error.join(", "), "testStatCombinaison");
383
470
  return;
384
471
  }
385
472
  function generateRandomStat(total = 100, max, min) {
@@ -400,6 +487,13 @@ function generateRandomStat(total = 100, max, min) {
400
487
  // Annotate the CommonJS export names for ESM import in node:
401
488
  0 && (module.exports = {
402
489
  COMMENT_REGEX,
490
+ DiceTypeError,
491
+ EmptyObjectError,
492
+ FormulaError,
493
+ MaxGreater,
494
+ NoStatisticsError,
495
+ TooManyDice,
496
+ TooManyStats,
403
497
  calculator,
404
498
  cleanedDice,
405
499
  diceRandomParse,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/dice.ts","../src/utils.ts","../src/verify_template.ts"],"sourcesContent":["export * from \"./dice\";\r\nexport * from \"./interface\";\r\nexport * from \"./utils\";\r\nexport * from \"./verify_template\";","/* eslint-disable no-useless-escape */\r\nimport { DiceRoller } from \"@dice-roller/rpg-dice-roller\";\r\nimport { evaluate } from \"mathjs\";\r\n\r\nimport { Compare, Modifier, Resultat, Sign } from \".\";\r\n\r\nexport const COMMENT_REGEX = /\\s+(#|\\/{2}|\\[|\\/\\*)(.*)/;\r\nconst SIGN_REGEX =/[><=!]+/;\r\nconst SIGN_REGEX_SPACE = /[><=!]+(\\S+)/;\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 (compareRegex) {\r\n\t\tdice = dice.replace(SIGN_REGEX_SPACE, \"\");\r\n\t\tconst calc = compareRegex[1];\r\n\t\tconst sign = calc.match(/[+-\\/\\*\\^]/)?.[0];\r\n\t\tconst compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];\r\n\t\tif (sign) {\r\n\t\t\tconst toCalc = calc.replace(SIGN_REGEX, \"\").replace(/\\s/g, \"\");\r\n\t\t\tconst total = evaluate(toCalc);\r\n\t\t\tdice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);\r\n\t\t\tcompare = {\r\n\t\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\t\tvalue: total,\r\n\t\t\t};\r\n\t\t} else compare = {\r\n\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\r\n\t\t\tvalue: parseInt(calc, 10),\r\n\t\t};\r\n\t}\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)\r\n\t\t\t\tvalue = calculator(sign, value, 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: parseInt(mod[2], 10),\r\n\t\t\t};\r\n\t\t}\r\n\t} \r\n\t\r\n\tif (dice.match(/\\d+?#(.*)/)) {\r\n\t\tconst diceArray = dice.split(\"#\");\r\n\t\tconst numberOfDice = 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 Error(`[error.invalidDice.withoutDice, common.space]: ${diceToRoll}`);\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};\r\n\t}\r\n\tconst roller = new DiceRoller();\r\n\tconst diceWithoutComment = dice.replace(COMMENT_REGEX, \"\");\r\n\ttry {\t\r\n\t\troller.roll(diceWithoutComment);\r\n\t} catch (error) {\r\n\t\tthrow new Error(`[error.invalidDice.withoutDice, common.space]: ${diceWithoutComment}`);\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};\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\tif (sign === \"^\") sign = \"**\";\r\n\treturn evaluate(`${total} ${sign} ${value}`);\r\n}\r\n\r\n\r\n\r\n","import { evaluate } from \"mathjs\";\r\nimport removeAccents from \"remove-accents\";\r\n\r\n/**\r\n * Escape regex string\r\n * @param string {string}\r\n */\r\nexport function escapeRegex(string: string) {\r\n\treturn string.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\r\n}\r\n\r\n\r\n/**\r\n * Replace the stat name by their value using stat and after evaluate any formula using `replaceFormulaInDice`\r\n * @param originalDice {dice}\r\n * @param stats {[name: string]: number}\r\n */\r\nexport function generateStatsDice(originalDice: string, stats?: {[name: string]: number}) {\r\n\tlet dice = originalDice;\r\n\tif (stats && Object.keys(stats).length > 0) {\r\n\t\t//damage field support adding statistic, like : 1d6 + strength\r\n\t\t//check if the value contains a statistic & calculate if it's okay\r\n\t\t//the dice will be converted before roll \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(removeAccents(stat)), \"gi\");\r\n\t\t\tif (dice.match(regex)) {\r\n\t\t\t\tconst statValue = stats[stat];\r\n\t\t\t\tdice = dice.replace(regex, statValue.toString());\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn replaceFormulaInDice(dice);\r\n\t\r\n}\r\n\r\n/**\r\n * Replace the {{}} in the dice string and evaluate the interior if any\r\n * @param dice {string}\r\n */\r\nexport function replaceFormulaInDice(dice: string) {\r\n\tconst formula = /(?<formula>\\{{2}(.+?)\\}{2})/gmi;\r\n\tconst formulaMatch = formula.exec(dice);\r\n\tif (formulaMatch?.groups?.formula) {\r\n\t\tconst formula = formulaMatch.groups.formula.replaceAll(\"{{\", \"\").replaceAll(\"}}\", \"\");\r\n\t\ttry {\r\n\t\t\tconst result = evaluate(formula);\r\n\t\t\treturn cleanedDice(dice.replace(formulaMatch.groups.formula, result.toString()));\r\n\t\t} catch (error) {\r\n\t\t\tthrow new Error(`[error.invalidFormula, common.space]: ${formulaMatch.groups.formula}`);\r\n\t\t}\r\n\t}\r\n\treturn cleanedDice(dice);\r\n}\r\n\r\n/**\r\n * Replace the ++ +- -- by their proper value:\r\n * - `++` = `+`\r\n * - `+-` = `-`\r\n * - `--` = `+`\r\n * @param dice {string}\r\n */\r\nexport function cleanedDice(dice: string) {\r\n\treturn dice.replaceAll(\"+-\", \"-\").replaceAll(\"--\", \"+\").replaceAll(\"++\", \"+\");\r\n}","/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport { evaluate } from \"mathjs\";\r\nimport {Random } from \"random-js\";\r\nimport removeAccents from \"remove-accents\";\r\n\r\nimport { Statistic, StatisticalTemplate } from \".\";\r\nimport { roll } from \"./dice\";\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(removeAccents(stat)), \"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}\t\r\n\ttry {\r\n\t\tif (!roll(replaceFormulaInDice(dice))) throw new Error(`[error.invalidDice.withoutDice, common.space] ${dice}`);\r\n\t\treturn testDice;\r\n\t} catch (error) {\r\n\t\tthrow new Error(`[error.invalidDice.withoutDice, common.space]: ${testDice}\\n${(error as Error).message}`);\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\tvalue = removeAccents(value);\r\n\tconst allStats = Object.keys(template.statistics).map(stat => removeAccents(stat).toLowerCase());\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[removeAccents(stat).toLowerCase()].max;\r\n\t\t\t\tmin = template.statistics[removeAccents(stat).toLowerCase()].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(stat => !template.statistics?.[stat].combinaison);\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(combinaison: {[name: string]: string}, stats: {[name: string]: string | number}) {\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 = removeAccents(combin);\r\n\t\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\t\tconst regex = new RegExp(removeAccents(statName), \"gi\");\r\n\t\t\tformula = formula.replace(regex, value.toString());\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tconst result = evaluate(formula);\r\n\t\t\tnewStats[stat] = result;\r\n\t\t} catch (error) {\r\n\t\t\tthrow new Error(`[error.invalidFormula, common.space]: ${stat}`);\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(combinaison: string, stats: {[name: string]: string | number}) {\r\n\tlet formula = removeAccents(combinaison);\r\n\tfor (const [statName, value] of Object.entries(stats)) {\r\n\t\tconst regex = new RegExp(removeAccents(statName), \"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 Error(`[error.invalidFormula, common.space]: ${combinaison}`);\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// eslint-disable-next-line @typescript-eslint/no-explicit-any\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\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 Error(\"[error.maxGreater]\");\t\t\t\t\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 ? removeAccents(dataValue.combinaison).toLowerCase() : 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\ttry {\r\n\t\t\tstatistiqueTemplate.diceType = template.diceType;\r\n\t\t\tconst cleanedDice = diceTypeRandomParse(template.diceType, statistiqueTemplate);\r\n\t\t\tconst rolled = roll(cleanedDice);\r\n\t\t\tif (!rolled) throw new Error(\"[error.invalidDice.withoutDice]\");\r\n\t\t} catch (e) {\r\n\t\t\tthrow new Error((e as Error).message);\r\n\t\t}\r\n\t}\r\n\r\n\t\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\r\n\t}\r\n\tif (template.total) {\r\n\t\tif (template.total <= 0)\r\n\t\t\ttemplate.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\ttry {\r\n\t\ttestDiceRegistered(statistiqueTemplate);\r\n\t\ttestStatCombinaison(statistiqueTemplate);\r\n\t} catch (error) {\r\n\t\tthrow new Error((error as Error).message);\r\n\t}\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 Error(\"[error.emptyObject]\");\r\n\tif (Object.keys(template.damage).length > 25) throw new Error(\"[error.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 Error(`[error.invalidDice, common.space] ${name}`);\r\n\t\t} catch (error) {\r\n\t\t\tthrow new Error(`[error.invalidDice, common.space] ${name}`);\r\n\t\t}\r\n\t}\r\n}\r\n\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(Object.entries(template.statistics).filter(([_, value]) => value.combinaison !== undefined));\r\n\tconst allOtherStats = Object.fromEntries(Object.entries(template.statistics).filter(([_, value]) => !value.combinaison));\t\r\n\tif (Object.keys(onlyCombinaisonStats).length===0) return;\r\n\tconst allStats = Object.keys(template.statistics).filter(stat => !template.statistics![stat].combinaison);\r\n\tif (allStats.length === 0) \r\n\t\tthrow new Error(\"[error.noStat]\");\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) \r\n\t\tthrow new Error(`[error.invalidFormula, common.space] ${error.join(\", \")}`);\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(total: number | undefined = 100, max?: number, min?: number) {\r\n\tlet randomStatValue = total + 1;\r\n\twhile (randomStatValue >= total) {\r\n\t\tconst random = new Random();\r\n\t\tif (max && min)\r\n\t\t\trandomStatValue = random.integer(min, max);\r\n\t\telse if (max)\r\n\t\t\trandomStatValue = random.integer(0, max);\r\n\t\telse if (min)\r\n\t\t\trandomStatValue = random.integer(min, total);\r\n\t\telse\r\n\t\t\trandomStatValue = random.integer(0, total);\r\n\t}\r\n\treturn randomStatValue;\r\n}\r\n\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,6BAA2B;AAC3B,oBAAyB;AAIlB,IAAM,gBAAgB;AAC7B,IAAM,aAAY;AAClB,IAAM,mBAAmB;AAMlB,SAAS,KAAK,MAAmC;AAEvD,MAAI,CAAC,KAAK,SAAS,GAAG;AAAG,WAAO;AAChC,QAAM,eAAe,KAAK,MAAM,gBAAgB;AAChD,MAAI;AACJ,MAAI,cAAc;AACjB,WAAO,KAAK,QAAQ,kBAAkB,EAAE;AACxC,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W;AACvB,UAAM,IAAI,MAAM,gBAAgB;AACjC,QAAM,QAAO,CAAC;AACd,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,oBAAoB,GAAG;AACjE,QAAI,UAAU,MAAM;AACpB,eAAW,CAAC,OAAO,IAAI,KAAK,OAAO,QAAQ,aAAa,GAAG;AAC1D,YAAM,EAAC,KAAK,IAAG,IAAI;AACnB,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;AAClB,UAAM,IAAI,MAAM,wCAAwC,MAAM,KAAK,IAAI,CAAC,EAAE;AAC3E;AACD;AASO,SAAS,mBAAmB,QAA4B,KAAK,KAAc,KAAc;AAC/F,MAAI,kBAAkB,QAAQ;AAC9B,SAAO,mBAAmB,OAAO;AAChC,UAAM,SAAS,IAAI,wBAAO;AAC1B,QAAI,OAAO;AACV,wBAAkB,OAAO,QAAQ,KAAK,GAAG;AAAA,aACjC;AACR,wBAAkB,OAAO,QAAQ,GAAG,GAAG;AAAA,aAC/B;AACR,wBAAkB,OAAO,QAAQ,KAAK,KAAK;AAAA;AAE3C,wBAAkB,OAAO,QAAQ,GAAG,KAAK;AAAA,EAC3C;AACA,SAAO;AACR;","names":["roller","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/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\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 (compareRegex) {\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, \"\");\n\t\tconst calc = compareRegex[1];\n\t\tconst sign = calc.match(/[+-\\/\\*\\^]/)?.[0];\n\t\tconst compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];\n\t\tif (sign) {\n\t\t\tconst toCalc = calc.replace(SIGN_REGEX, \"\").replace(/\\s/g, \"\");\n\t\t\tconst total = evaluate(toCalc);\n\t\t\t//biome-ignore lint/style/noParameterAssign: I need to assign the value to the variable\n\t\t\tdice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);\n\t\t\tcompare = {\n\t\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\n\t\t\t\tvalue: total,\n\t\t\t};\n\t\t} else\n\t\t\tcompare = {\n\t\t\t\tsign: compareSign as \"<\" | \">\" | \">=\" | \"<=\" | \"=\" | \"!=\" | \"==\",\n\t\t\t\tvalue: Number.parseInt(calc, 10),\n\t\t\t};\n\t}\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\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};\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};\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","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 randomStatVal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