@dicelette/core 1.28.2 → 1.28.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 +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +21 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -312,9 +312,10 @@ declare function includeDiceType(dice: string, diceType?: string, userStats?: bo
|
|
|
312
312
|
* @param {Engine|null} engine The random engine to use, default to nodeCrypto
|
|
313
313
|
* @param {boolean} pity Whether to enable pity system (reroll on failure) or not
|
|
314
314
|
* @param {boolean} sort Whether to sort the dice results or not
|
|
315
|
+
* @param {string} comment Optional comment to attach to the result. If provided, skips extracting the comment from the dice string (assumes dice is already clean).
|
|
315
316
|
* @returns {Resultat|undefined} The result of the roll
|
|
316
317
|
*/
|
|
317
|
-
declare function roll(dice: string, engine?: Engine | null, pity?: boolean, sort?: SortOrder): Resultat | undefined;
|
|
318
|
+
declare function roll(dice: string, engine?: Engine | null, pity?: boolean, sort?: SortOrder, comment?: string): Resultat | undefined;
|
|
318
319
|
declare function replaceInFormula(element: string, diceResult: Resultat, compareResult: {
|
|
319
320
|
dice: string;
|
|
320
321
|
compare: Compare | undefined;
|
|
@@ -367,6 +368,18 @@ declare function findBestRecord(record: Record<string, string>, searchTerm: stri
|
|
|
367
368
|
declare function replaceUnknown(dice: string, replacer: string): string;
|
|
368
369
|
declare function verifyStatMatcherPattern(dice: string, replaceUnknow?: string): string;
|
|
369
370
|
|
|
371
|
+
/**
|
|
372
|
+
* Splits a dice string into the dice expression and its trailing comment.
|
|
373
|
+
* Comments are preceded by whitespace and start with #, //, [, or /*.
|
|
374
|
+
* The returned comment does NOT include the marker prefix.
|
|
375
|
+
* @example
|
|
376
|
+
* splitDiceComment("1d6 # attack") // => { dice: "1d6", comment: "attack" }
|
|
377
|
+
* splitDiceComment("2d8+3") // => { dice: "2d8+3", comment: undefined }
|
|
378
|
+
*/
|
|
379
|
+
declare function splitDiceComment(dice: string): {
|
|
380
|
+
dice: string;
|
|
381
|
+
comment: string | undefined;
|
|
382
|
+
};
|
|
370
383
|
/**
|
|
371
384
|
* Escape regex string
|
|
372
385
|
* @param string {string}
|
|
@@ -477,4 +490,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
|
|
|
477
490
|
*/
|
|
478
491
|
declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
|
|
479
492
|
|
|
480
|
-
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, type FormulaHintResult, MIN_THRESHOLD_MATCH, MaxGreater, type Modifier, NORMALIZE_SINGLE_DICE, NoStatisticsError, OPTIONAL_COMMENT, REMOVER_PATTERN, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculateSimilarity, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, findBestRecord, findBestStatMatch, generateRandomStat, generateStatsDice, getCachedRegex, getEngine, getEngineId, includeDiceType, isNumber, levenshteinDistance, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, replaceUnknown, resolveFormulaHint, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyStatMatcherPattern, verifyTemplateValue };
|
|
493
|
+
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, type FormulaHintResult, MIN_THRESHOLD_MATCH, MaxGreater, type Modifier, NORMALIZE_SINGLE_DICE, NoStatisticsError, OPTIONAL_COMMENT, REMOVER_PATTERN, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculateSimilarity, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, findBestRecord, findBestStatMatch, generateRandomStat, generateStatsDice, getCachedRegex, getEngine, getEngineId, includeDiceType, isNumber, levenshteinDistance, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, replaceUnknown, resolveFormulaHint, roll, splitDiceComment, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyStatMatcherPattern, verifyTemplateValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -312,9 +312,10 @@ declare function includeDiceType(dice: string, diceType?: string, userStats?: bo
|
|
|
312
312
|
* @param {Engine|null} engine The random engine to use, default to nodeCrypto
|
|
313
313
|
* @param {boolean} pity Whether to enable pity system (reroll on failure) or not
|
|
314
314
|
* @param {boolean} sort Whether to sort the dice results or not
|
|
315
|
+
* @param {string} comment Optional comment to attach to the result. If provided, skips extracting the comment from the dice string (assumes dice is already clean).
|
|
315
316
|
* @returns {Resultat|undefined} The result of the roll
|
|
316
317
|
*/
|
|
317
|
-
declare function roll(dice: string, engine?: Engine | null, pity?: boolean, sort?: SortOrder): Resultat | undefined;
|
|
318
|
+
declare function roll(dice: string, engine?: Engine | null, pity?: boolean, sort?: SortOrder, comment?: string): Resultat | undefined;
|
|
318
319
|
declare function replaceInFormula(element: string, diceResult: Resultat, compareResult: {
|
|
319
320
|
dice: string;
|
|
320
321
|
compare: Compare | undefined;
|
|
@@ -367,6 +368,18 @@ declare function findBestRecord(record: Record<string, string>, searchTerm: stri
|
|
|
367
368
|
declare function replaceUnknown(dice: string, replacer: string): string;
|
|
368
369
|
declare function verifyStatMatcherPattern(dice: string, replaceUnknow?: string): string;
|
|
369
370
|
|
|
371
|
+
/**
|
|
372
|
+
* Splits a dice string into the dice expression and its trailing comment.
|
|
373
|
+
* Comments are preceded by whitespace and start with #, //, [, or /*.
|
|
374
|
+
* The returned comment does NOT include the marker prefix.
|
|
375
|
+
* @example
|
|
376
|
+
* splitDiceComment("1d6 # attack") // => { dice: "1d6", comment: "attack" }
|
|
377
|
+
* splitDiceComment("2d8+3") // => { dice: "2d8+3", comment: undefined }
|
|
378
|
+
*/
|
|
379
|
+
declare function splitDiceComment(dice: string): {
|
|
380
|
+
dice: string;
|
|
381
|
+
comment: string | undefined;
|
|
382
|
+
};
|
|
370
383
|
/**
|
|
371
384
|
* Escape regex string
|
|
372
385
|
* @param string {string}
|
|
@@ -477,4 +490,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
|
|
|
477
490
|
*/
|
|
478
491
|
declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
|
|
479
492
|
|
|
480
|
-
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, type FormulaHintResult, MIN_THRESHOLD_MATCH, MaxGreater, type Modifier, NORMALIZE_SINGLE_DICE, NoStatisticsError, OPTIONAL_COMMENT, REMOVER_PATTERN, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculateSimilarity, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, findBestRecord, findBestStatMatch, generateRandomStat, generateStatsDice, getCachedRegex, getEngine, getEngineId, includeDiceType, isNumber, levenshteinDistance, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, replaceUnknown, resolveFormulaHint, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyStatMatcherPattern, verifyTemplateValue };
|
|
493
|
+
export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, type FormulaHintResult, MIN_THRESHOLD_MATCH, MaxGreater, type Modifier, NORMALIZE_SINGLE_DICE, NoStatisticsError, OPTIONAL_COMMENT, REMOVER_PATTERN, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, calculateSimilarity, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, findBestRecord, findBestStatMatch, generateRandomStat, generateStatsDice, getCachedRegex, getEngine, getEngineId, includeDiceType, isNumber, levenshteinDistance, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, replaceUnknown, resolveFormulaHint, roll, splitDiceComment, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyStatMatcherPattern, verifyTemplateValue };
|
package/dist/index.js
CHANGED
|
@@ -62,6 +62,7 @@ __export(index_exports, {
|
|
|
62
62
|
replaceUnknown: () => replaceUnknown,
|
|
63
63
|
resolveFormulaHint: () => resolveFormulaHint,
|
|
64
64
|
roll: () => roll,
|
|
65
|
+
splitDiceComment: () => splitDiceComment,
|
|
65
66
|
standardizeDice: () => standardizeDice,
|
|
66
67
|
templateSchema: () => templateSchema,
|
|
67
68
|
testDiceRegistered: () => testDiceRegistered,
|
|
@@ -285,10 +286,6 @@ var import_mathjs10 = require("mathjs");
|
|
|
285
286
|
var import_rpg_dice_roller7 = require("@dice-roller/rpg-dice-roller");
|
|
286
287
|
var import_mathjs8 = require("mathjs");
|
|
287
288
|
|
|
288
|
-
// src/dice/compare.ts
|
|
289
|
-
var import_rpg_dice_roller4 = require("@dice-roller/rpg-dice-roller");
|
|
290
|
-
var import_mathjs2 = require("mathjs");
|
|
291
|
-
|
|
292
289
|
// src/utils.ts
|
|
293
290
|
var import_uniformize2 = require("uniformize");
|
|
294
291
|
var import_rpg_dice_roller3 = require("@dice-roller/rpg-dice-roller");
|
|
@@ -507,6 +504,12 @@ function generateRandomStat(total = 100, max, min, engine = import_rpg_dice_roll
|
|
|
507
504
|
}
|
|
508
505
|
|
|
509
506
|
// src/utils.ts
|
|
507
|
+
function splitDiceComment(dice) {
|
|
508
|
+
const match = /\s+(#|\/{2}|\[|\/\*)(?<comment>.*)/i.exec(dice);
|
|
509
|
+
if (!match?.groups) return { dice: dice.trimEnd(), comment: void 0 };
|
|
510
|
+
const comment = match.groups.comment.trim() || void 0;
|
|
511
|
+
return { dice: dice.slice(0, match.index).trimEnd(), comment };
|
|
512
|
+
}
|
|
510
513
|
function escapeRegex(string) {
|
|
511
514
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
512
515
|
}
|
|
@@ -543,6 +546,8 @@ function createCriticalCustom(dice, customCritical, template, engine = import_rp
|
|
|
543
546
|
}
|
|
544
547
|
|
|
545
548
|
// src/dice/compare.ts
|
|
549
|
+
var import_rpg_dice_roller4 = require("@dice-roller/rpg-dice-roller");
|
|
550
|
+
var import_mathjs2 = require("mathjs");
|
|
546
551
|
function isTrivialComparison(maxValue, minValue, compare) {
|
|
547
552
|
const canSucceed = canComparisonSucceed(maxValue, compare, minValue);
|
|
548
553
|
const canFail = canComparisonFail(maxValue, compare, minValue);
|
|
@@ -1133,7 +1138,7 @@ function setSortOrder(toRoll, sort) {
|
|
|
1133
1138
|
}
|
|
1134
1139
|
function prepareDice(diceInput) {
|
|
1135
1140
|
let dice = standardizeDice(replaceFormulaInDice(diceInput)).replace(/^\+/, "").replaceAll("=>", ">=").replaceAll("=<", "<=").trimStart();
|
|
1136
|
-
dice = dice.replaceAll(
|
|
1141
|
+
dice = dice.replaceAll(REMOVER_PATTERN.CRITICAL_BLOCK, "").trimEnd();
|
|
1137
1142
|
const explodingSuccess = normalizeExplodingSuccess(dice);
|
|
1138
1143
|
if (explodingSuccess) dice = explodingSuccess.dice;
|
|
1139
1144
|
let diceDisplay;
|
|
@@ -1185,9 +1190,8 @@ function handleBulkRolls(dice, isCurlyBulk, bulkContent, compare, explodingSucce
|
|
|
1185
1190
|
const bulkProcessContent = isCurlyBulk ? bulkContent : dice;
|
|
1186
1191
|
const diceArray = bulkProcessContent.split("#");
|
|
1187
1192
|
const numberOfDice = Number.parseInt(diceArray[0], 10);
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
const comments = commentsMatch ? commentsMatch[2] : void 0;
|
|
1193
|
+
const { dice: diceToRollBase, comment: comments } = splitDiceComment(diceArray[1]);
|
|
1194
|
+
let diceToRoll = diceToRollBase;
|
|
1191
1195
|
let curlyCompare;
|
|
1192
1196
|
if (isCurlyBulk) {
|
|
1193
1197
|
const curlyCompareRegex = diceToRoll.match(SIGN_REGEX_SPACE);
|
|
@@ -1372,7 +1376,7 @@ function handlePitySystem(dice, compare, diceRoll, roller, engine) {
|
|
|
1372
1376
|
}
|
|
1373
1377
|
|
|
1374
1378
|
// src/roll.ts
|
|
1375
|
-
function roll(dice, engine = import_rpg_dice_roller8.NumberGenerator.engines.nodeCrypto, pity, sort) {
|
|
1379
|
+
function roll(dice, engine = import_rpg_dice_roller8.NumberGenerator.engines.nodeCrypto, pity, sort, comment) {
|
|
1376
1380
|
if (sort === "none" /* None */) sort = void 0;
|
|
1377
1381
|
const prepared = prepareDice(dice);
|
|
1378
1382
|
if (!prepared.dice.includes("d")) return void 0;
|
|
@@ -1415,8 +1419,10 @@ function roll(dice, engine = import_rpg_dice_roller8.NumberGenerator.engines.nod
|
|
|
1415
1419
|
}
|
|
1416
1420
|
const roller = new import_rpg_dice_roller8.DiceRoller();
|
|
1417
1421
|
import_rpg_dice_roller8.NumberGenerator.generator.engine = engine;
|
|
1418
|
-
|
|
1419
|
-
|
|
1422
|
+
const splitResult = splitDiceComment(processedDice);
|
|
1423
|
+
const diceBase = comment !== void 0 ? processedDice.trimEnd() : splitResult.dice;
|
|
1424
|
+
const resolvedComment = comment ?? splitResult.comment;
|
|
1425
|
+
const diceWithoutComment = setSortOrder(diceBase, sort);
|
|
1420
1426
|
let diceRoll;
|
|
1421
1427
|
try {
|
|
1422
1428
|
diceRoll = roller.roll(diceWithoutComment);
|
|
@@ -1432,8 +1438,6 @@ function roll(dice, engine = import_rpg_dice_roller8.NumberGenerator.engines.nod
|
|
|
1432
1438
|
);
|
|
1433
1439
|
compare.trivial = trivial ? true : void 0;
|
|
1434
1440
|
}
|
|
1435
|
-
const commentMatch = processedDice.match(COMMENT_REGEX);
|
|
1436
|
-
const comment = commentMatch ? commentMatch[2] : void 0;
|
|
1437
1441
|
let rerollCount = 0;
|
|
1438
1442
|
let pityResult;
|
|
1439
1443
|
if (pity && compare) {
|
|
@@ -1450,7 +1454,7 @@ function roll(dice, engine = import_rpg_dice_roller8.NumberGenerator.engines.nod
|
|
|
1450
1454
|
return {
|
|
1451
1455
|
...pityResult,
|
|
1452
1456
|
dice: prepared.isSimpleCurly ? finalDiceDisplay : processedDice,
|
|
1453
|
-
comment,
|
|
1457
|
+
comment: resolvedComment,
|
|
1454
1458
|
compare,
|
|
1455
1459
|
modifier: modificator,
|
|
1456
1460
|
pityLogs: rerollCount,
|
|
@@ -1472,7 +1476,7 @@ function roll(dice, engine = import_rpg_dice_roller8.NumberGenerator.engines.nod
|
|
|
1472
1476
|
return {
|
|
1473
1477
|
dice: prepared.isSimpleCurly ? finalDiceDisplay : prepared.diceDisplay,
|
|
1474
1478
|
result: resultOutput,
|
|
1475
|
-
comment,
|
|
1479
|
+
comment: resolvedComment,
|
|
1476
1480
|
compare: compare ? compare : void 0,
|
|
1477
1481
|
modifier: modificator,
|
|
1478
1482
|
total: successes,
|
|
@@ -1483,7 +1487,7 @@ function roll(dice, engine = import_rpg_dice_roller8.NumberGenerator.engines.nod
|
|
|
1483
1487
|
return {
|
|
1484
1488
|
dice: prepared.isSimpleCurly ? finalDiceDisplay : processedDice,
|
|
1485
1489
|
result: resultOutput,
|
|
1486
|
-
comment,
|
|
1490
|
+
comment: resolvedComment,
|
|
1487
1491
|
compare: compare ? compare : void 0,
|
|
1488
1492
|
modifier: modificator,
|
|
1489
1493
|
total: roller.total,
|
|
@@ -1700,6 +1704,7 @@ function replaceInFormula(element, diceResult, compareResult, res, engine = impo
|
|
|
1700
1704
|
replaceUnknown,
|
|
1701
1705
|
resolveFormulaHint,
|
|
1702
1706
|
roll,
|
|
1707
|
+
splitDiceComment,
|
|
1703
1708
|
standardizeDice,
|
|
1704
1709
|
templateSchema,
|
|
1705
1710
|
testDiceRegistered,
|