@dicelette/core 1.0.10 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ declare const COMMENT_REGEX: RegExp;
2
+ declare function roll(dice: string): Resultat | undefined;
3
+ declare function calculator(sign: Sign, value: number, total: number): number;
4
+
5
+ interface Resultat {
6
+ dice: string;
7
+ result: string;
8
+ comment?: string;
9
+ compare?: Compare | undefined;
10
+ modifier?: Modifier;
11
+ }
12
+ interface Compare {
13
+ sign: "<" | ">" | ">=" | "<=" | "=" | "!=" | "==";
14
+ value: number;
15
+ }
16
+ type Sign = "+" | "-" | "*" | "/" | "%" | "^" | "**";
17
+ interface Modifier {
18
+ sign?: Sign;
19
+ value: number;
20
+ }
21
+ type Statistic = {
22
+ [name: string]: {
23
+ max?: number;
24
+ min?: number;
25
+ combinaison?: string;
26
+ };
27
+ };
28
+ interface StatisticalTemplate {
29
+ charName?: boolean;
30
+ statistics?: Statistic;
31
+ total?: number;
32
+ diceType?: string;
33
+ critical?: Critical;
34
+ damage?: {
35
+ [name: string]: string;
36
+ };
37
+ }
38
+ interface Critical {
39
+ success?: number;
40
+ failure?: number;
41
+ }
42
+
43
+ declare function escapeRegex(string: string): string;
44
+ declare function generateStatsDice(originalDice: string, stats?: {
45
+ [name: string]: number;
46
+ }): string;
47
+ declare function replaceFormulaInDice(dice: string): string;
48
+ declare function cleanedDice(dice: string): string;
49
+
50
+ declare function evalStatsDice(testDice: string, stats?: {
51
+ [name: string]: number;
52
+ }): string;
53
+ declare function diceRandomParse(value: string, template: StatisticalTemplate): string;
54
+ declare function diceTypeRandomParse(dice: string, template: StatisticalTemplate): string;
55
+ declare function evalCombinaison(combinaison: {
56
+ [name: string]: string;
57
+ }, stats: {
58
+ [name: string]: string | number;
59
+ }): {
60
+ [name: string]: number;
61
+ };
62
+ declare function evalOneCombinaison(combinaison: string, stats: {
63
+ [name: string]: string | number;
64
+ }): any;
65
+ declare function verifyTemplateValue(template: any): StatisticalTemplate;
66
+ declare function testDamageRoll(template: StatisticalTemplate): void;
67
+ declare function testCombinaison(template: StatisticalTemplate): void;
68
+ declare function generateRandomStat(total?: number | undefined, max?: number, min?: number): number;
69
+
70
+ export { COMMENT_REGEX, type Compare, type Critical, type Modifier, type Resultat, type Sign, type Statistic, type StatisticalTemplate, calculator, cleanedDice, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, replaceFormulaInDice, roll, testCombinaison, testDamageRoll, verifyTemplateValue };
@@ -0,0 +1,70 @@
1
+ declare const COMMENT_REGEX: RegExp;
2
+ declare function roll(dice: string): Resultat | undefined;
3
+ declare function calculator(sign: Sign, value: number, total: number): number;
4
+
5
+ interface Resultat {
6
+ dice: string;
7
+ result: string;
8
+ comment?: string;
9
+ compare?: Compare | undefined;
10
+ modifier?: Modifier;
11
+ }
12
+ interface Compare {
13
+ sign: "<" | ">" | ">=" | "<=" | "=" | "!=" | "==";
14
+ value: number;
15
+ }
16
+ type Sign = "+" | "-" | "*" | "/" | "%" | "^" | "**";
17
+ interface Modifier {
18
+ sign?: Sign;
19
+ value: number;
20
+ }
21
+ type Statistic = {
22
+ [name: string]: {
23
+ max?: number;
24
+ min?: number;
25
+ combinaison?: string;
26
+ };
27
+ };
28
+ interface StatisticalTemplate {
29
+ charName?: boolean;
30
+ statistics?: Statistic;
31
+ total?: number;
32
+ diceType?: string;
33
+ critical?: Critical;
34
+ damage?: {
35
+ [name: string]: string;
36
+ };
37
+ }
38
+ interface Critical {
39
+ success?: number;
40
+ failure?: number;
41
+ }
42
+
43
+ declare function escapeRegex(string: string): string;
44
+ declare function generateStatsDice(originalDice: string, stats?: {
45
+ [name: string]: number;
46
+ }): string;
47
+ declare function replaceFormulaInDice(dice: string): string;
48
+ declare function cleanedDice(dice: string): string;
49
+
50
+ declare function evalStatsDice(testDice: string, stats?: {
51
+ [name: string]: number;
52
+ }): string;
53
+ declare function diceRandomParse(value: string, template: StatisticalTemplate): string;
54
+ declare function diceTypeRandomParse(dice: string, template: StatisticalTemplate): string;
55
+ declare function evalCombinaison(combinaison: {
56
+ [name: string]: string;
57
+ }, stats: {
58
+ [name: string]: string | number;
59
+ }): {
60
+ [name: string]: number;
61
+ };
62
+ declare function evalOneCombinaison(combinaison: string, stats: {
63
+ [name: string]: string | number;
64
+ }): any;
65
+ declare function verifyTemplateValue(template: any): StatisticalTemplate;
66
+ declare function testDamageRoll(template: StatisticalTemplate): void;
67
+ declare function testCombinaison(template: StatisticalTemplate): void;
68
+ declare function generateRandomStat(total?: number | undefined, max?: number, min?: number): number;
69
+
70
+ export { COMMENT_REGEX, type Compare, type Critical, type Modifier, type Resultat, type Sign, type Statistic, type StatisticalTemplate, calculator, cleanedDice, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, replaceFormulaInDice, roll, testCombinaison, testDamageRoll, verifyTemplateValue };
package/dist/index.js ADDED
@@ -0,0 +1,406 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ COMMENT_REGEX: () => COMMENT_REGEX,
34
+ calculator: () => calculator,
35
+ cleanedDice: () => cleanedDice,
36
+ diceRandomParse: () => diceRandomParse,
37
+ diceTypeRandomParse: () => diceTypeRandomParse,
38
+ escapeRegex: () => escapeRegex,
39
+ evalCombinaison: () => evalCombinaison,
40
+ evalOneCombinaison: () => evalOneCombinaison,
41
+ evalStatsDice: () => evalStatsDice,
42
+ generateRandomStat: () => generateRandomStat,
43
+ generateStatsDice: () => generateStatsDice,
44
+ replaceFormulaInDice: () => replaceFormulaInDice,
45
+ roll: () => roll,
46
+ testCombinaison: () => testCombinaison,
47
+ testDamageRoll: () => testDamageRoll,
48
+ verifyTemplateValue: () => verifyTemplateValue
49
+ });
50
+ module.exports = __toCommonJS(src_exports);
51
+
52
+ // src/dice.ts
53
+ var import_rpg_dice_roller = require("@dice-roller/rpg-dice-roller");
54
+ var import_mathjs = require("mathjs");
55
+ var COMMENT_REGEX = /\s+(#|\/{2}|\[|\/\*)(.*)/;
56
+ var SIGN_REGEX = /[><=!]+/;
57
+ var SIGN_REGEX_SPACE = /[><=!]+(\S+)/;
58
+ function roll(dice) {
59
+ if (!dice.includes("d"))
60
+ return void 0;
61
+ const compareRegex = dice.match(SIGN_REGEX_SPACE);
62
+ let compare;
63
+ if (compareRegex) {
64
+ dice = dice.replace(SIGN_REGEX_SPACE, "");
65
+ const calc = compareRegex[1];
66
+ const sign = calc.match(/[+-\/\*\^]/)?.[0];
67
+ const compareSign = compareRegex[0].match(SIGN_REGEX)?.[0];
68
+ if (sign) {
69
+ const toCalc = calc.replace(SIGN_REGEX, "").replace(/\s/g, "");
70
+ const total = (0, import_mathjs.evaluate)(toCalc);
71
+ dice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);
72
+ compare = {
73
+ sign: compareSign,
74
+ value: total
75
+ };
76
+ } else
77
+ compare = {
78
+ sign: compareSign,
79
+ value: parseInt(calc, 10)
80
+ };
81
+ }
82
+ const modifier = dice.matchAll(/(\+|\-|%|\/|\^|\*|\*{2})(\d+)/gi);
83
+ let modificator;
84
+ for (const mod of modifier) {
85
+ if (modificator) {
86
+ const sign = modificator.sign;
87
+ let value = modificator.value;
88
+ if (sign)
89
+ value = calculator(sign, value, parseInt(mod[2], 10));
90
+ modificator = {
91
+ sign: mod[1],
92
+ value
93
+ };
94
+ } else {
95
+ modificator = {
96
+ sign: mod[1],
97
+ value: parseInt(mod[2], 10)
98
+ };
99
+ }
100
+ }
101
+ if (dice.match(/\d+?#(.*)/)) {
102
+ const diceArray = dice.split("#");
103
+ const numberOfDice = parseInt(diceArray[0], 10);
104
+ const diceToRoll = diceArray[1].replace(COMMENT_REGEX, "");
105
+ const commentsMatch = diceArray[1].match(COMMENT_REGEX);
106
+ const comments = commentsMatch ? commentsMatch[2] : void 0;
107
+ const roller2 = new import_rpg_dice_roller.DiceRoller();
108
+ for (let i = 0; i < numberOfDice; i++) {
109
+ roller2.roll(diceToRoll);
110
+ }
111
+ return {
112
+ dice: diceToRoll,
113
+ result: roller2.output,
114
+ comment: comments,
115
+ compare: compare ? compare : void 0,
116
+ modifier: modificator
117
+ };
118
+ }
119
+ const roller = new import_rpg_dice_roller.DiceRoller();
120
+ const diceWithoutComment = dice.replace(COMMENT_REGEX, "");
121
+ roller.roll(diceWithoutComment);
122
+ const commentMatch = dice.match(COMMENT_REGEX);
123
+ const comment = commentMatch ? commentMatch[2] : void 0;
124
+ return {
125
+ dice,
126
+ result: roller.output,
127
+ comment,
128
+ compare: compare ? compare : void 0,
129
+ modifier: modificator
130
+ };
131
+ }
132
+ function calculator(sign, value, total) {
133
+ if (sign === "^")
134
+ sign = "**";
135
+ return (0, import_mathjs.evaluate)(`${total} ${sign} ${value}`);
136
+ }
137
+
138
+ // src/utils.ts
139
+ var import_mathjs2 = require("mathjs");
140
+ var import_remove_accents = __toESM(require("remove-accents"));
141
+ function escapeRegex(string) {
142
+ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
143
+ }
144
+ function generateStatsDice(originalDice, stats) {
145
+ let dice = originalDice;
146
+ if (stats && Object.keys(stats).length > 0) {
147
+ const allStats = Object.keys(stats);
148
+ for (const stat of allStats) {
149
+ const regex = new RegExp(escapeRegex((0, import_remove_accents.default)(stat)), "gi");
150
+ if (dice.match(regex)) {
151
+ const statValue = stats[stat];
152
+ dice = dice.replace(regex, statValue.toString());
153
+ }
154
+ }
155
+ }
156
+ return replaceFormulaInDice(dice);
157
+ }
158
+ function replaceFormulaInDice(dice) {
159
+ const formula = /(?<formula>\{{2}(.+?)\}{2})/gmi;
160
+ const formulaMatch = formula.exec(dice);
161
+ if (formulaMatch?.groups?.formula) {
162
+ const formula2 = formulaMatch.groups.formula.replaceAll("{{", "").replaceAll("}}", "");
163
+ try {
164
+ const result = (0, import_mathjs2.evaluate)(formula2);
165
+ return cleanedDice(dice.replace(formulaMatch.groups.formula, result.toString()));
166
+ } catch (error) {
167
+ throw new Error(`[error.invalidFormula, common.space]: ${formulaMatch.groups.formula}`);
168
+ }
169
+ }
170
+ return cleanedDice(dice);
171
+ }
172
+ function cleanedDice(dice) {
173
+ return dice.replaceAll("+-", "-").replaceAll("--", "+").replaceAll("++", "+");
174
+ }
175
+
176
+ // src/verify_template.ts
177
+ var import_mathjs3 = require("mathjs");
178
+ var import_random_js = require("random-js");
179
+ var import_remove_accents2 = __toESM(require("remove-accents"));
180
+ function evalStatsDice(testDice, stats) {
181
+ let dice = testDice;
182
+ if (stats && Object.keys(stats).length > 0) {
183
+ const allStats = Object.keys(stats);
184
+ for (const stat of allStats) {
185
+ const regex = new RegExp(escapeRegex((0, import_remove_accents2.default)(stat)), "gi");
186
+ if (testDice.match(regex)) {
187
+ const statValue = stats[stat];
188
+ dice = testDice.replace(regex, statValue.toString());
189
+ }
190
+ }
191
+ }
192
+ try {
193
+ if (!roll(replaceFormulaInDice(dice)))
194
+ throw new Error(`[error.invalidDice.withoutDice, common.space] ${dice}`);
195
+ return testDice;
196
+ } catch (error) {
197
+ throw new Error(`[error.invalidDice.withoutDice, common.space]: ${testDice}
198
+ ${error.message}`);
199
+ }
200
+ }
201
+ function diceRandomParse(value, template) {
202
+ if (!template.statistics)
203
+ return value;
204
+ value = (0, import_remove_accents2.default)(value);
205
+ const allStats = Object.keys(template.statistics).map((stat) => (0, import_remove_accents2.default)(stat).toLowerCase());
206
+ let newDice = value;
207
+ for (const stat of allStats) {
208
+ const regex = new RegExp(escapeRegex(stat), "gi");
209
+ if (value.match(regex)) {
210
+ let max = void 0;
211
+ let min = void 0;
212
+ const stats = template.statistics?.[stat];
213
+ if (stats) {
214
+ max = template.statistics[(0, import_remove_accents2.default)(stat).toLowerCase()].max;
215
+ min = template.statistics[(0, import_remove_accents2.default)(stat).toLowerCase()].min;
216
+ }
217
+ const total = template.total || 100;
218
+ const randomStatValue = generateRandomStat(total, max, min);
219
+ newDice = value.replace(regex, randomStatValue.toString());
220
+ }
221
+ }
222
+ return replaceFormulaInDice(newDice);
223
+ }
224
+ function diceTypeRandomParse(dice, template) {
225
+ if (!template.statistics)
226
+ return dice;
227
+ const firstStatNotCombinaison = Object.keys(template.statistics).find((stat) => !template.statistics?.[stat].combinaison);
228
+ if (!firstStatNotCombinaison)
229
+ return dice;
230
+ const stats = template.statistics[firstStatNotCombinaison];
231
+ const { min, max } = stats;
232
+ const total = template.total || 100;
233
+ const randomStatValue = generateRandomStat(total, max, min);
234
+ return replaceFormulaInDice(dice.replace("$", randomStatValue.toString()));
235
+ }
236
+ function evalCombinaison(combinaison, stats) {
237
+ const newStats = {};
238
+ for (const [stat, combin] of Object.entries(combinaison)) {
239
+ let formula = (0, import_remove_accents2.default)(combin);
240
+ for (const [statName, value] of Object.entries(stats)) {
241
+ const regex = new RegExp((0, import_remove_accents2.default)(statName), "gi");
242
+ formula = formula.replace(regex, value.toString());
243
+ }
244
+ try {
245
+ const result = (0, import_mathjs3.evaluate)(formula);
246
+ newStats[stat] = result;
247
+ } catch (error) {
248
+ throw new Error(`[error.invalidFormula, common.space]: ${stat}`);
249
+ }
250
+ }
251
+ return newStats;
252
+ }
253
+ function evalOneCombinaison(combinaison, stats) {
254
+ let formula = (0, import_remove_accents2.default)(combinaison);
255
+ for (const [statName, value] of Object.entries(stats)) {
256
+ const regex = new RegExp((0, import_remove_accents2.default)(statName), "gi");
257
+ formula = formula.replace(regex, value.toString());
258
+ }
259
+ try {
260
+ return (0, import_mathjs3.evaluate)(formula);
261
+ } catch (error) {
262
+ throw new Error(`[error.invalidFormula, common.space]: ${combinaison}`);
263
+ }
264
+ }
265
+ function verifyTemplateValue(template) {
266
+ const statistiqueTemplate = {
267
+ diceType: "",
268
+ statistics: {}
269
+ };
270
+ if (!template.statistics)
271
+ statistiqueTemplate.statistics = void 0;
272
+ else if (template.statistics && Object.keys(template.statistics).length > 0) {
273
+ for (const [key, value] of Object.entries(template.statistics)) {
274
+ const dataValue = value;
275
+ if (dataValue.max && dataValue.min && dataValue.max <= dataValue.min)
276
+ throw new Error("[error.maxGreater]");
277
+ if (dataValue.max && dataValue.max <= 0)
278
+ dataValue.max = void 0;
279
+ if (dataValue.min && dataValue.min <= 0)
280
+ dataValue.min = void 0;
281
+ let formula = dataValue.combinaison ? (0, import_remove_accents2.default)(dataValue.combinaison).toLowerCase() : void 0;
282
+ formula = formula && formula.trim().length > 0 ? formula : void 0;
283
+ if (!statistiqueTemplate.statistics) {
284
+ statistiqueTemplate.statistics = {};
285
+ }
286
+ statistiqueTemplate.statistics[key] = {
287
+ max: dataValue.max,
288
+ min: dataValue.min,
289
+ combinaison: formula || void 0
290
+ };
291
+ }
292
+ }
293
+ if (template.diceType) {
294
+ try {
295
+ statistiqueTemplate.diceType = template.diceType;
296
+ diceTypeRandomParse(template.diceType, statistiqueTemplate);
297
+ } catch (e) {
298
+ throw new Error(e.message);
299
+ }
300
+ }
301
+ if (template.critical && Object.keys(template.critical).length > 0) {
302
+ statistiqueTemplate.critical = {
303
+ failure: template.critical.failure ?? void 0,
304
+ success: template.critical.success ?? void 0
305
+ };
306
+ }
307
+ if (template.total) {
308
+ if (template.total <= 0)
309
+ template.total = void 0;
310
+ statistiqueTemplate.total = template.total;
311
+ }
312
+ if (template.charName)
313
+ statistiqueTemplate.charName = template.charName;
314
+ if (template.damage)
315
+ statistiqueTemplate.damage = template.damage;
316
+ try {
317
+ testDamageRoll(statistiqueTemplate);
318
+ testCombinaison(statistiqueTemplate);
319
+ } catch (error) {
320
+ throw new Error(error.message);
321
+ }
322
+ return statistiqueTemplate;
323
+ }
324
+ function testDamageRoll(template) {
325
+ if (!template.damage)
326
+ return;
327
+ if (Object.keys(template.damage).length === 0)
328
+ throw new Error("[error.emptyObject]");
329
+ if (Object.keys(template.damage).length > 25)
330
+ throw new Error("[error.tooManyDice]");
331
+ for (const [name, dice] of Object.entries(template.damage)) {
332
+ if (!dice)
333
+ continue;
334
+ const randomDiceParsed = diceRandomParse(dice, template);
335
+ try {
336
+ roll(randomDiceParsed);
337
+ } catch (error) {
338
+ throw new Error(`[error.invalidDice, common.space] ${name}`);
339
+ }
340
+ }
341
+ }
342
+ function testCombinaison(template) {
343
+ if (!template.statistics)
344
+ return;
345
+ const onlyCombinaisonStats = Object.fromEntries(Object.entries(template.statistics).filter(([_, value]) => value.combinaison !== void 0));
346
+ const allOtherStats = Object.fromEntries(Object.entries(template.statistics).filter(([_, value]) => !value.combinaison));
347
+ if (Object.keys(onlyCombinaisonStats).length === 0)
348
+ return;
349
+ const allStats = Object.keys(template.statistics).filter((stat) => !template.statistics[stat].combinaison);
350
+ if (allStats.length === 0)
351
+ throw new Error("[error.noStat]");
352
+ const error = [];
353
+ for (const [stat, value] of Object.entries(onlyCombinaisonStats)) {
354
+ let formula = value.combinaison;
355
+ for (const [other, data] of Object.entries(allOtherStats)) {
356
+ const { max, min } = data;
357
+ const total = template.total || 100;
358
+ const randomStatValue = generateRandomStat(total, max, min);
359
+ const regex = new RegExp(other, "gi");
360
+ formula = formula.replace(regex, randomStatValue.toString());
361
+ }
362
+ try {
363
+ (0, import_mathjs3.evaluate)(formula);
364
+ } catch (e) {
365
+ error.push(stat);
366
+ }
367
+ }
368
+ if (error.length > 0)
369
+ throw new Error(`[error.invalidFormula, common.space] ${error.join(", ")}`);
370
+ return;
371
+ }
372
+ function generateRandomStat(total = 100, max, min) {
373
+ let randomStatValue = total + 1;
374
+ while (randomStatValue >= total) {
375
+ const random = new import_random_js.Random();
376
+ if (max && min)
377
+ randomStatValue = random.integer(min, max);
378
+ else if (max)
379
+ randomStatValue = random.integer(0, max);
380
+ else if (min)
381
+ randomStatValue = random.integer(min, total);
382
+ else
383
+ randomStatValue = random.integer(0, total);
384
+ }
385
+ return randomStatValue;
386
+ }
387
+ // Annotate the CommonJS export names for ESM import in node:
388
+ 0 && (module.exports = {
389
+ COMMENT_REGEX,
390
+ calculator,
391
+ cleanedDice,
392
+ diceRandomParse,
393
+ diceTypeRandomParse,
394
+ escapeRegex,
395
+ evalCombinaison,
396
+ evalOneCombinaison,
397
+ evalStatsDice,
398
+ generateRandomStat,
399
+ generateStatsDice,
400
+ replaceFormulaInDice,
401
+ roll,
402
+ testCombinaison,
403
+ testDamageRoll,
404
+ verifyTemplateValue
405
+ });
406
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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\troller.roll(diceToRoll);\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\troller.roll(diceWithoutComment);\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\tdiceTypeRandomParse(template.diceType, statistiqueTemplate);\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\ttestDamageRoll(statistiqueTemplate);\r\n\t\ttestCombinaison(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 testDamageRoll(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\troll(randomDiceParsed);\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 testCombinaison(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,UAAM,OAAO,aAAa,CAAC;AAC3B,UAAM,OAAO,KAAK,MAAM,YAAY,IAAI,CAAC;AACzC,UAAM,cAAc,aAAa,CAAC,EAAE,MAAM,UAAU,IAAI,CAAC;AACzD,QAAI,MAAM;AACT,YAAM,SAAS,KAAK,QAAQ,YAAY,EAAE,EAAE,QAAQ,OAAO,EAAE;AAC7D,YAAM,YAAQ,wBAAS,MAAM;AAC7B,aAAO,KAAK,QAAQ,kBAAkB,GAAG,WAAW,GAAG,KAAK,EAAE;AAC9D,gBAAU;AAAA,QACT,MAAM;AA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