@dicelette/core 1.12.1 → 1.12.3
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 +13 -15
- package/dist/index.d.ts +13 -15
- package/dist/index.js +183 -185
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +182 -184
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -215,13 +215,11 @@ declare function generateStatsDice(originalDice: string, stats?: Record<string,
|
|
215
215
|
*/
|
216
216
|
declare function replaceFormulaInDice(dice: string): string;
|
217
217
|
/**
|
218
|
-
*
|
219
|
-
*
|
220
|
-
*
|
221
|
-
* - `--` = `+`
|
222
|
-
* @param dice {string}
|
218
|
+
* Verify if a value is a number, even if it's a "number" string
|
219
|
+
* @param value {unknown}
|
220
|
+
* @returns {boolean}
|
223
221
|
*/
|
224
|
-
declare function
|
222
|
+
declare function isNumber(value: unknown): boolean;
|
225
223
|
|
226
224
|
/**
|
227
225
|
* Verify if the provided dice work with random value
|
@@ -332,33 +330,33 @@ declare const templateSchema: z.ZodObject<{
|
|
332
330
|
combinaison: z.ZodOptional<z.ZodEffects<z.ZodString, string | undefined, string>>;
|
333
331
|
exclude: z.ZodOptional<z.ZodBoolean>;
|
334
332
|
}, "strip", z.ZodTypeAny, {
|
335
|
-
max?: number | undefined;
|
336
333
|
min?: number | undefined;
|
334
|
+
max?: number | undefined;
|
337
335
|
combinaison?: string | undefined;
|
338
336
|
exclude?: boolean | undefined;
|
339
337
|
}, {
|
340
|
-
max?: number | undefined;
|
341
338
|
min?: number | undefined;
|
339
|
+
max?: number | undefined;
|
342
340
|
combinaison?: string | undefined;
|
343
341
|
exclude?: boolean | undefined;
|
344
342
|
}>, {
|
345
|
-
max?: number | undefined;
|
346
343
|
min?: number | undefined;
|
344
|
+
max?: number | undefined;
|
347
345
|
combinaison?: string | undefined;
|
348
346
|
exclude?: boolean | undefined;
|
349
347
|
}, {
|
350
|
-
max?: number | undefined;
|
351
348
|
min?: number | undefined;
|
349
|
+
max?: number | undefined;
|
352
350
|
combinaison?: string | undefined;
|
353
351
|
exclude?: boolean | undefined;
|
354
352
|
}>>>, Record<string, {
|
355
|
-
max?: number | undefined;
|
356
353
|
min?: number | undefined;
|
354
|
+
max?: number | undefined;
|
357
355
|
combinaison?: string | undefined;
|
358
356
|
exclude?: boolean | undefined;
|
359
357
|
}> | undefined, Record<string, {
|
360
|
-
max?: number | undefined;
|
361
358
|
min?: number | undefined;
|
359
|
+
max?: number | undefined;
|
362
360
|
combinaison?: string | undefined;
|
363
361
|
exclude?: boolean | undefined;
|
364
362
|
}> | undefined>;
|
@@ -411,8 +409,8 @@ declare const templateSchema: z.ZodObject<{
|
|
411
409
|
total?: number | undefined;
|
412
410
|
charName?: boolean | undefined;
|
413
411
|
statistics?: Record<string, {
|
414
|
-
max?: number | undefined;
|
415
412
|
min?: number | undefined;
|
413
|
+
max?: number | undefined;
|
416
414
|
combinaison?: string | undefined;
|
417
415
|
exclude?: boolean | undefined;
|
418
416
|
}> | undefined;
|
@@ -432,8 +430,8 @@ declare const templateSchema: z.ZodObject<{
|
|
432
430
|
total?: number | undefined;
|
433
431
|
charName?: boolean | undefined;
|
434
432
|
statistics?: Record<string, {
|
435
|
-
max?: number | undefined;
|
436
433
|
min?: number | undefined;
|
434
|
+
max?: number | undefined;
|
437
435
|
combinaison?: string | undefined;
|
438
436
|
exclude?: boolean | undefined;
|
439
437
|
}> | undefined;
|
@@ -459,4 +457,4 @@ interface StatisticalSchema extends StatisticalTemplate {
|
|
459
457
|
$schema?: string;
|
460
458
|
}
|
461
459
|
|
462
|
-
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator,
|
460
|
+
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, isNumber, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
|
package/dist/index.d.ts
CHANGED
@@ -215,13 +215,11 @@ declare function generateStatsDice(originalDice: string, stats?: Record<string,
|
|
215
215
|
*/
|
216
216
|
declare function replaceFormulaInDice(dice: string): string;
|
217
217
|
/**
|
218
|
-
*
|
219
|
-
*
|
220
|
-
*
|
221
|
-
* - `--` = `+`
|
222
|
-
* @param dice {string}
|
218
|
+
* Verify if a value is a number, even if it's a "number" string
|
219
|
+
* @param value {unknown}
|
220
|
+
* @returns {boolean}
|
223
221
|
*/
|
224
|
-
declare function
|
222
|
+
declare function isNumber(value: unknown): boolean;
|
225
223
|
|
226
224
|
/**
|
227
225
|
* Verify if the provided dice work with random value
|
@@ -332,33 +330,33 @@ declare const templateSchema: z.ZodObject<{
|
|
332
330
|
combinaison: z.ZodOptional<z.ZodEffects<z.ZodString, string | undefined, string>>;
|
333
331
|
exclude: z.ZodOptional<z.ZodBoolean>;
|
334
332
|
}, "strip", z.ZodTypeAny, {
|
335
|
-
max?: number | undefined;
|
336
333
|
min?: number | undefined;
|
334
|
+
max?: number | undefined;
|
337
335
|
combinaison?: string | undefined;
|
338
336
|
exclude?: boolean | undefined;
|
339
337
|
}, {
|
340
|
-
max?: number | undefined;
|
341
338
|
min?: number | undefined;
|
339
|
+
max?: number | undefined;
|
342
340
|
combinaison?: string | undefined;
|
343
341
|
exclude?: boolean | undefined;
|
344
342
|
}>, {
|
345
|
-
max?: number | undefined;
|
346
343
|
min?: number | undefined;
|
344
|
+
max?: number | undefined;
|
347
345
|
combinaison?: string | undefined;
|
348
346
|
exclude?: boolean | undefined;
|
349
347
|
}, {
|
350
|
-
max?: number | undefined;
|
351
348
|
min?: number | undefined;
|
349
|
+
max?: number | undefined;
|
352
350
|
combinaison?: string | undefined;
|
353
351
|
exclude?: boolean | undefined;
|
354
352
|
}>>>, Record<string, {
|
355
|
-
max?: number | undefined;
|
356
353
|
min?: number | undefined;
|
354
|
+
max?: number | undefined;
|
357
355
|
combinaison?: string | undefined;
|
358
356
|
exclude?: boolean | undefined;
|
359
357
|
}> | undefined, Record<string, {
|
360
|
-
max?: number | undefined;
|
361
358
|
min?: number | undefined;
|
359
|
+
max?: number | undefined;
|
362
360
|
combinaison?: string | undefined;
|
363
361
|
exclude?: boolean | undefined;
|
364
362
|
}> | undefined>;
|
@@ -411,8 +409,8 @@ declare const templateSchema: z.ZodObject<{
|
|
411
409
|
total?: number | undefined;
|
412
410
|
charName?: boolean | undefined;
|
413
411
|
statistics?: Record<string, {
|
414
|
-
max?: number | undefined;
|
415
412
|
min?: number | undefined;
|
413
|
+
max?: number | undefined;
|
416
414
|
combinaison?: string | undefined;
|
417
415
|
exclude?: boolean | undefined;
|
418
416
|
}> | undefined;
|
@@ -432,8 +430,8 @@ declare const templateSchema: z.ZodObject<{
|
|
432
430
|
total?: number | undefined;
|
433
431
|
charName?: boolean | undefined;
|
434
432
|
statistics?: Record<string, {
|
435
|
-
max?: number | undefined;
|
436
433
|
min?: number | undefined;
|
434
|
+
max?: number | undefined;
|
437
435
|
combinaison?: string | undefined;
|
438
436
|
exclude?: boolean | undefined;
|
439
437
|
}> | undefined;
|
@@ -459,4 +457,4 @@ interface StatisticalSchema extends StatisticalTemplate {
|
|
459
457
|
$schema?: string;
|
460
458
|
}
|
461
459
|
|
462
|
-
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator,
|
460
|
+
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculator, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, isNumber, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
|
package/dist/index.js
CHANGED
@@ -32,7 +32,6 @@ __export(src_exports, {
|
|
32
32
|
TooManyDice: () => TooManyDice,
|
33
33
|
TooManyStats: () => TooManyStats,
|
34
34
|
calculator: () => calculator,
|
35
|
-
cleanedDice: () => cleanedDice,
|
36
35
|
createCriticalCustom: () => createCriticalCustom,
|
37
36
|
diceRandomParse: () => diceRandomParse,
|
38
37
|
diceTypeRandomParse: () => diceTypeRandomParse,
|
@@ -42,6 +41,7 @@ __export(src_exports, {
|
|
42
41
|
evalStatsDice: () => evalStatsDice,
|
43
42
|
generateRandomStat: () => generateRandomStat,
|
44
43
|
generateStatsDice: () => generateStatsDice,
|
44
|
+
isNumber: () => isNumber,
|
45
45
|
replaceFormulaInDice: () => replaceFormulaInDice,
|
46
46
|
roll: () => roll,
|
47
47
|
standardizeDice: () => standardizeDice,
|
@@ -54,78 +54,58 @@ module.exports = __toCommonJS(src_exports);
|
|
54
54
|
|
55
55
|
// src/dice.ts
|
56
56
|
var import_rpg_dice_roller = require("@dice-roller/rpg-dice-roller");
|
57
|
-
var
|
57
|
+
var import_mathjs2 = require("mathjs");
|
58
58
|
|
59
|
-
// src/
|
60
|
-
var
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
}
|
83
|
-
};
|
84
|
-
var MaxGreater = class extends Error {
|
85
|
-
name;
|
86
|
-
value;
|
87
|
-
max;
|
88
|
-
constructor(value, max) {
|
89
|
-
super(value.toString());
|
90
|
-
this.name = "Max_Greater";
|
91
|
-
this.value = value;
|
92
|
-
this.max = max;
|
93
|
-
}
|
94
|
-
};
|
95
|
-
var EmptyObjectError = class extends Error {
|
96
|
-
name;
|
97
|
-
constructor() {
|
98
|
-
super();
|
99
|
-
this.name = "Empty_Object";
|
100
|
-
}
|
101
|
-
};
|
102
|
-
var TooManyDice = class extends Error {
|
103
|
-
name;
|
104
|
-
constructor() {
|
105
|
-
super();
|
106
|
-
this.name = "Too_Many_Dice";
|
107
|
-
}
|
108
|
-
};
|
109
|
-
var TooManyStats = class extends Error {
|
110
|
-
name;
|
111
|
-
constructor() {
|
112
|
-
super();
|
113
|
-
this.name = "Too_Many_Stats";
|
59
|
+
// src/utils.ts
|
60
|
+
var import_mathjs = require("mathjs");
|
61
|
+
var import_uniformize = require("uniformize");
|
62
|
+
function escapeRegex(string) {
|
63
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
64
|
+
}
|
65
|
+
function standardizeDice(dice) {
|
66
|
+
return dice.replace(
|
67
|
+
/(\[[^\]]+\])|([^[]+)/g,
|
68
|
+
(match, insideBrackets, outsideText) => insideBrackets ? insideBrackets : outsideText.standardize()
|
69
|
+
);
|
70
|
+
}
|
71
|
+
function generateStatsDice(originalDice, stats, dollarValue) {
|
72
|
+
let dice = originalDice.standardize();
|
73
|
+
if (stats && Object.keys(stats).length > 0) {
|
74
|
+
const allStats = Object.keys(stats);
|
75
|
+
for (const stat of allStats) {
|
76
|
+
const regex = new RegExp(`(?!\\[)${escapeRegex(stat.standardize())}(?!\\])`, "gi");
|
77
|
+
if (dice.match(regex)) {
|
78
|
+
const statValue = stats[stat];
|
79
|
+
dice = dice.replace(regex, statValue.toString());
|
80
|
+
}
|
81
|
+
}
|
114
82
|
}
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
83
|
+
if (dollarValue) dice = dice.replaceAll("$", dollarValue);
|
84
|
+
return replaceFormulaInDice(dice);
|
85
|
+
}
|
86
|
+
function replaceFormulaInDice(dice) {
|
87
|
+
const formula = /(?<formula>\{{2}(.+?)}{2})/gim;
|
88
|
+
let match;
|
89
|
+
let modifiedDice = dice;
|
90
|
+
while ((match = formula.exec(dice)) !== null) {
|
91
|
+
if (match.groups?.formula) {
|
92
|
+
const formulae = match.groups.formula.replaceAll("{{", "").replaceAll("}}", "");
|
93
|
+
try {
|
94
|
+
const result = (0, import_mathjs.evaluate)(formulae);
|
95
|
+
modifiedDice = modifiedDice.replace(match.groups.formula, result.toString());
|
96
|
+
} catch (error) {
|
97
|
+
throw new FormulaError(match.groups.formula, "replaceFormulasInDice", error);
|
98
|
+
}
|
99
|
+
}
|
121
100
|
}
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
101
|
+
return cleanedDice(modifiedDice);
|
102
|
+
}
|
103
|
+
function cleanedDice(dice) {
|
104
|
+
return dice.replaceAll("+-", "-").replaceAll("--", "+").replaceAll("++", "+").trimEnd();
|
105
|
+
}
|
106
|
+
function isNumber(value) {
|
107
|
+
return value !== void 0 && (typeof value === "number" || !Number.isNaN(Number(value)) && typeof value === "string" && value.trim().length > 0);
|
108
|
+
}
|
129
109
|
|
130
110
|
// src/dice.ts
|
131
111
|
function getCompare(dice, compareRegex) {
|
@@ -137,7 +117,7 @@ function getCompare(dice, compareRegex) {
|
|
137
117
|
if (sign) {
|
138
118
|
const toCalc = calc.replace(SIGN_REGEX, "").replace(/\s/g, "").replace(/;(.*)/, "");
|
139
119
|
const rCompare = rollCompare(toCalc);
|
140
|
-
const total = (0,
|
120
|
+
const total = (0, import_mathjs2.evaluate)(rCompare.value.toString());
|
141
121
|
dice = dice.replace(SIGN_REGEX_SPACE, `${compareSign}${total}`);
|
142
122
|
compare = {
|
143
123
|
sign: compareSign,
|
@@ -157,11 +137,10 @@ function getCompare(dice, compareRegex) {
|
|
157
137
|
return { dice, compare };
|
158
138
|
}
|
159
139
|
function rollCompare(value) {
|
160
|
-
const isNumber = (value2) => typeof value2 === "number" || !Number.isNaN(Number(value2)) && typeof value2 === "string";
|
161
140
|
if (isNumber(value)) return { value: Number.parseInt(value, 10) };
|
162
141
|
const rollComp = roll(value);
|
163
142
|
if (!rollComp?.total)
|
164
|
-
return { value: (0,
|
143
|
+
return { value: (0, import_mathjs2.evaluate)(value), diceResult: value };
|
165
144
|
return {
|
166
145
|
dice: value,
|
167
146
|
value: rollComp.total,
|
@@ -201,7 +180,7 @@ function getModifier(dice) {
|
|
201
180
|
return modificator;
|
202
181
|
}
|
203
182
|
function roll(dice) {
|
204
|
-
dice = standardizeDice(dice);
|
183
|
+
dice = standardizeDice(dice).replace(/^\+/, "").trimStart();
|
205
184
|
if (!dice.includes("d")) return void 0;
|
206
185
|
const compareRegex = dice.match(SIGN_REGEX_SPACE);
|
207
186
|
let compare;
|
@@ -255,7 +234,7 @@ function roll(dice) {
|
|
255
234
|
}
|
256
235
|
function calculator(sign, value, total) {
|
257
236
|
if (sign === "^") sign = "**";
|
258
|
-
return (0,
|
237
|
+
return (0, import_mathjs2.evaluate)(`${total} ${sign} ${value}`);
|
259
238
|
}
|
260
239
|
function inverseSign(sign) {
|
261
240
|
switch (sign) {
|
@@ -285,7 +264,7 @@ function replaceInFormula(element, diceResult, compareResult, res) {
|
|
285
264
|
const invertedSign = res ? compareResult.compare.sign : inverseSign(compareResult.compare.sign);
|
286
265
|
let evaluateRoll;
|
287
266
|
try {
|
288
|
-
evaluateRoll = (0,
|
267
|
+
evaluateRoll = (0, import_mathjs2.evaluate)(compareResult.dice);
|
289
268
|
return `${validSign} ${diceAll}: ${formule} = ${evaluateRoll}${invertedSign}${compareResult.compare?.value}`;
|
290
269
|
} catch (error) {
|
291
270
|
const evaluateRoll2 = roll(compareResult.dice);
|
@@ -300,7 +279,7 @@ function compareSignFormule(toRoll, compareRegex, element, diceResult) {
|
|
300
279
|
const toCompare = `${compareResult.dice}${compareResult.compare?.sign}${compareResult.compare?.value}`;
|
301
280
|
let res;
|
302
281
|
try {
|
303
|
-
res = (0,
|
282
|
+
res = (0, import_mathjs2.evaluate)(toCompare);
|
304
283
|
} catch (error) {
|
305
284
|
res = roll(toCompare);
|
306
285
|
}
|
@@ -309,7 +288,7 @@ function compareSignFormule(toRoll, compareRegex, element, diceResult) {
|
|
309
288
|
} else if (res instanceof Object) {
|
310
289
|
const diceResult2 = res;
|
311
290
|
if (diceResult2.compare) {
|
312
|
-
const toEvaluate = (0,
|
291
|
+
const toEvaluate = (0, import_mathjs2.evaluate)(
|
313
292
|
`${diceResult2.total}${diceResult2.compare.sign}${diceResult2.compare.value}`
|
314
293
|
);
|
315
294
|
const sign = toEvaluate ? "\u2713" : "\u2715";
|
@@ -377,7 +356,7 @@ function sharedRolls(dice) {
|
|
377
356
|
diceResult.dice
|
378
357
|
);
|
379
358
|
try {
|
380
|
-
const evaluated = (0,
|
359
|
+
const evaluated = (0, import_mathjs2.evaluate)(toRoll);
|
381
360
|
results.push(`\u25C8 ${comment}${diceAll}: ${formule} = ${evaluated}`);
|
382
361
|
total += Number.parseInt(evaluated, 10);
|
383
362
|
} catch (error) {
|
@@ -403,114 +382,10 @@ function sharedRolls(dice) {
|
|
403
382
|
};
|
404
383
|
}
|
405
384
|
|
406
|
-
// src/utils.ts
|
407
|
-
var import_mathjs2 = require("mathjs");
|
408
|
-
var import_uniformize = require("uniformize");
|
409
|
-
function escapeRegex(string) {
|
410
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
411
|
-
}
|
412
|
-
function standardizeDice(dice) {
|
413
|
-
return dice.replace(
|
414
|
-
/(\[[^\]]+\])|([^[]+)/g,
|
415
|
-
(match, insideBrackets, outsideText) => insideBrackets ? insideBrackets : outsideText.standardize()
|
416
|
-
);
|
417
|
-
}
|
418
|
-
function generateStatsDice(originalDice, stats, dollarValue) {
|
419
|
-
let dice = originalDice.standardize();
|
420
|
-
if (stats && Object.keys(stats).length > 0) {
|
421
|
-
const allStats = Object.keys(stats);
|
422
|
-
for (const stat of allStats) {
|
423
|
-
const regex = new RegExp(`(?!\\[)${escapeRegex(stat.standardize())}(?!\\])`, "gi");
|
424
|
-
if (dice.match(regex)) {
|
425
|
-
const statValue = stats[stat];
|
426
|
-
dice = dice.replace(regex, statValue.toString());
|
427
|
-
}
|
428
|
-
}
|
429
|
-
}
|
430
|
-
if (dollarValue) dice = dice.replaceAll("$", dollarValue);
|
431
|
-
return replaceFormulaInDice(dice);
|
432
|
-
}
|
433
|
-
function replaceFormulaInDice(dice) {
|
434
|
-
const formula = /(?<formula>\{{2}(.+?)}{2})/gim;
|
435
|
-
let match;
|
436
|
-
let modifiedDice = dice;
|
437
|
-
while ((match = formula.exec(dice)) !== null) {
|
438
|
-
if (match.groups?.formula) {
|
439
|
-
const formulae = match.groups.formula.replaceAll("{{", "").replaceAll("}}", "");
|
440
|
-
try {
|
441
|
-
const result = (0, import_mathjs2.evaluate)(formulae);
|
442
|
-
if (result instanceof Object || typeof result === "function") continue;
|
443
|
-
modifiedDice = modifiedDice.replace(match.groups.formula, result.toString());
|
444
|
-
} catch (error) {
|
445
|
-
throw new FormulaError(match.groups.formula, "replaceFormulasInDice", error);
|
446
|
-
}
|
447
|
-
}
|
448
|
-
}
|
449
|
-
return cleanedDice(modifiedDice);
|
450
|
-
}
|
451
|
-
function cleanedDice(dice) {
|
452
|
-
return dice.replaceAll("+-", "-").replaceAll("--", "+").replaceAll("++", "+").trimEnd();
|
453
|
-
}
|
454
|
-
|
455
385
|
// src/verify_template.ts
|
456
386
|
var import_mathjs3 = require("mathjs");
|
457
387
|
var import_random_js = require("random-js");
|
458
388
|
var import_uniformize2 = require("uniformize");
|
459
|
-
|
460
|
-
// src/interfaces/zod.ts
|
461
|
-
var import_zod = require("zod");
|
462
|
-
var statisticValueSchema = import_zod.z.object({
|
463
|
-
max: import_zod.z.number().positive().optional(),
|
464
|
-
min: import_zod.z.number().positive().optional(),
|
465
|
-
combinaison: import_zod.z.string().transform((str) => str.trim() || void 0).optional(),
|
466
|
-
exclude: import_zod.z.boolean().optional()
|
467
|
-
}).superRefine((data, ctx) => {
|
468
|
-
if (data.max !== void 0 && data.min !== void 0 && data.max <= data.min) {
|
469
|
-
ctx.addIssue({
|
470
|
-
code: "custom",
|
471
|
-
message: `Max_Greater; ${data.min}; ${data.max}`,
|
472
|
-
path: ["max"]
|
473
|
-
});
|
474
|
-
}
|
475
|
-
});
|
476
|
-
var statisticSchema = import_zod.z.record(statisticValueSchema).optional().refine((stats) => !stats || Object.keys(stats).length <= 25, {
|
477
|
-
message: "TooManyStats"
|
478
|
-
});
|
479
|
-
var criticalSchema = import_zod.z.object({
|
480
|
-
success: import_zod.z.string().or(import_zod.z.number().positive()).optional(),
|
481
|
-
failure: import_zod.z.string().or(import_zod.z.number().positive()).optional()
|
482
|
-
}).transform((values) => {
|
483
|
-
if (values.success === "") values.success = void 0;
|
484
|
-
if (values.failure === "") values.failure = void 0;
|
485
|
-
if (values.failure === 0) values.failure = void 0;
|
486
|
-
if (values.success === 0) values.success = void 0;
|
487
|
-
values.success = Number.parseInt(values.success, 10);
|
488
|
-
values.failure = Number.parseInt(values.failure, 10);
|
489
|
-
return values;
|
490
|
-
});
|
491
|
-
var criticalValueSchema = import_zod.z.object({
|
492
|
-
sign: import_zod.z.enum(["<", ">", "<=", ">=", "!=", "=="]),
|
493
|
-
value: import_zod.z.string(),
|
494
|
-
onNaturalDice: import_zod.z.boolean().optional(),
|
495
|
-
affectSkill: import_zod.z.boolean().optional()
|
496
|
-
});
|
497
|
-
var damageSchema = import_zod.z.record(import_zod.z.string()).optional().refine((stats) => !stats || Object.keys(stats).length <= 25, {
|
498
|
-
message: "TooManyDice"
|
499
|
-
});
|
500
|
-
var customCriticalSchema = import_zod.z.record(criticalValueSchema).optional().refine((stats) => !stats || Object.keys(stats).length <= 22, {
|
501
|
-
message: "TooManyDice"
|
502
|
-
});
|
503
|
-
var templateSchema = import_zod.z.object({
|
504
|
-
charName: import_zod.z.boolean().optional(),
|
505
|
-
statistics: statisticSchema,
|
506
|
-
total: import_zod.z.number().min(0).optional(),
|
507
|
-
diceType: import_zod.z.string().optional(),
|
508
|
-
critical: criticalSchema.optional(),
|
509
|
-
customCritical: customCriticalSchema,
|
510
|
-
damage: damageSchema
|
511
|
-
});
|
512
|
-
|
513
|
-
// src/verify_template.ts
|
514
389
|
function evalStatsDice(testDice, allStats) {
|
515
390
|
let dice = testDice.trimEnd();
|
516
391
|
if (allStats && Object.keys(allStats).length > 0) {
|
@@ -595,7 +470,6 @@ function evalOneCombinaison(combinaison, stats) {
|
|
595
470
|
}
|
596
471
|
function convertNumber(number) {
|
597
472
|
if (!number) return void 0;
|
598
|
-
const isNumber = (value) => typeof value === "number" || !Number.isNaN(Number(value)) && typeof value === "string";
|
599
473
|
if (number.toString().length === 0) return void 0;
|
600
474
|
if (isNumber(number)) return Number.parseInt(number.toString(), 10);
|
601
475
|
return void 0;
|
@@ -707,6 +581,130 @@ function generateRandomStat(total = 100, max, min) {
|
|
707
581
|
}
|
708
582
|
return randomStatValue;
|
709
583
|
}
|
584
|
+
|
585
|
+
// src/errors.ts
|
586
|
+
var DiceTypeError = class extends Error {
|
587
|
+
dice;
|
588
|
+
cause;
|
589
|
+
method;
|
590
|
+
constructor(dice, cause, method) {
|
591
|
+
super(dice);
|
592
|
+
this.name = "Invalid_Dice_Type";
|
593
|
+
this.dice = dice;
|
594
|
+
this.cause = cause;
|
595
|
+
this.method = method;
|
596
|
+
}
|
597
|
+
};
|
598
|
+
var FormulaError = class extends Error {
|
599
|
+
formula;
|
600
|
+
cause;
|
601
|
+
method;
|
602
|
+
constructor(formula, cause, method) {
|
603
|
+
super(formula);
|
604
|
+
this.name = "Invalid_Formula";
|
605
|
+
this.formula = formula;
|
606
|
+
this.cause = cause;
|
607
|
+
this.method = method;
|
608
|
+
}
|
609
|
+
};
|
610
|
+
var MaxGreater = class extends Error {
|
611
|
+
name;
|
612
|
+
value;
|
613
|
+
max;
|
614
|
+
constructor(value, max) {
|
615
|
+
super(value.toString());
|
616
|
+
this.name = "Max_Greater";
|
617
|
+
this.value = value;
|
618
|
+
this.max = max;
|
619
|
+
}
|
620
|
+
};
|
621
|
+
var EmptyObjectError = class extends Error {
|
622
|
+
name;
|
623
|
+
constructor() {
|
624
|
+
super();
|
625
|
+
this.name = "Empty_Object";
|
626
|
+
}
|
627
|
+
};
|
628
|
+
var TooManyDice = class extends Error {
|
629
|
+
name;
|
630
|
+
constructor() {
|
631
|
+
super();
|
632
|
+
this.name = "Too_Many_Dice";
|
633
|
+
}
|
634
|
+
};
|
635
|
+
var TooManyStats = class extends Error {
|
636
|
+
name;
|
637
|
+
constructor() {
|
638
|
+
super();
|
639
|
+
this.name = "Too_Many_Stats";
|
640
|
+
}
|
641
|
+
};
|
642
|
+
var NoStatisticsError = class extends Error {
|
643
|
+
name;
|
644
|
+
constructor() {
|
645
|
+
super();
|
646
|
+
this.name = "No_Statistics";
|
647
|
+
}
|
648
|
+
};
|
649
|
+
|
650
|
+
// src/interfaces/constant.ts
|
651
|
+
var COMMENT_REGEX = /\s+(#|\/{2}|\[|\/\*)(?<comment>.*)/;
|
652
|
+
var SIGN_REGEX = /[><=!]+/;
|
653
|
+
var SIGN_REGEX_SPACE = /[><=!]+(\S+)/;
|
654
|
+
var SYMBOL_DICE = "&";
|
655
|
+
|
656
|
+
// src/interfaces/zod.ts
|
657
|
+
var import_zod = require("zod");
|
658
|
+
var statisticValueSchema = import_zod.z.object({
|
659
|
+
max: import_zod.z.number().positive().optional(),
|
660
|
+
min: import_zod.z.number().positive().optional(),
|
661
|
+
combinaison: import_zod.z.string().transform((str) => str.trim() || void 0).optional(),
|
662
|
+
exclude: import_zod.z.boolean().optional()
|
663
|
+
}).superRefine((data, ctx) => {
|
664
|
+
if (data.max !== void 0 && data.min !== void 0 && data.max <= data.min) {
|
665
|
+
ctx.addIssue({
|
666
|
+
code: "custom",
|
667
|
+
message: `Max_Greater; ${data.min}; ${data.max}`,
|
668
|
+
path: ["max"]
|
669
|
+
});
|
670
|
+
}
|
671
|
+
});
|
672
|
+
var statisticSchema = import_zod.z.record(statisticValueSchema).optional().refine((stats) => !stats || Object.keys(stats).length <= 25, {
|
673
|
+
message: "TooManyStats"
|
674
|
+
});
|
675
|
+
var criticalSchema = import_zod.z.object({
|
676
|
+
success: import_zod.z.string().or(import_zod.z.number().positive()).optional(),
|
677
|
+
failure: import_zod.z.string().or(import_zod.z.number().positive()).optional()
|
678
|
+
}).transform((values) => {
|
679
|
+
if (values.success === "") values.success = void 0;
|
680
|
+
if (values.failure === "") values.failure = void 0;
|
681
|
+
if (values.failure === 0) values.failure = void 0;
|
682
|
+
if (values.success === 0) values.success = void 0;
|
683
|
+
values.success = Number.parseInt(values.success, 10);
|
684
|
+
values.failure = Number.parseInt(values.failure, 10);
|
685
|
+
return values;
|
686
|
+
});
|
687
|
+
var criticalValueSchema = import_zod.z.object({
|
688
|
+
sign: import_zod.z.enum(["<", ">", "<=", ">=", "!=", "=="]),
|
689
|
+
value: import_zod.z.string(),
|
690
|
+
onNaturalDice: import_zod.z.boolean().optional(),
|
691
|
+
affectSkill: import_zod.z.boolean().optional()
|
692
|
+
});
|
693
|
+
var damageSchema = import_zod.z.record(import_zod.z.string()).optional().refine((stats) => !stats || Object.keys(stats).length <= 25, {
|
694
|
+
message: "TooManyDice"
|
695
|
+
});
|
696
|
+
var customCriticalSchema = import_zod.z.record(criticalValueSchema).optional().refine((stats) => !stats || Object.keys(stats).length <= 22, {
|
697
|
+
message: "TooManyDice"
|
698
|
+
});
|
699
|
+
var templateSchema = import_zod.z.object({
|
700
|
+
charName: import_zod.z.boolean().optional(),
|
701
|
+
statistics: statisticSchema,
|
702
|
+
total: import_zod.z.number().min(0).optional(),
|
703
|
+
diceType: import_zod.z.string().optional(),
|
704
|
+
critical: criticalSchema.optional(),
|
705
|
+
customCritical: customCriticalSchema,
|
706
|
+
damage: damageSchema
|
707
|
+
});
|
710
708
|
// Annotate the CommonJS export names for ESM import in node:
|
711
709
|
0 && (module.exports = {
|
712
710
|
COMMENT_REGEX,
|
@@ -721,7 +719,6 @@ function generateRandomStat(total = 100, max, min) {
|
|
721
719
|
TooManyDice,
|
722
720
|
TooManyStats,
|
723
721
|
calculator,
|
724
|
-
cleanedDice,
|
725
722
|
createCriticalCustom,
|
726
723
|
diceRandomParse,
|
727
724
|
diceTypeRandomParse,
|
@@ -731,6 +728,7 @@ function generateRandomStat(total = 100, max, min) {
|
|
731
728
|
evalStatsDice,
|
732
729
|
generateRandomStat,
|
733
730
|
generateStatsDice,
|
731
|
+
isNumber,
|
734
732
|
replaceFormulaInDice,
|
735
733
|
roll,
|
736
734
|
standardizeDice,
|