@dicelette/core 1.28.1 → 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 CHANGED
@@ -312,14 +312,40 @@ 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;
321
322
  }, res: boolean, engine?: Engine | null, pity?: boolean): string;
322
323
 
324
+ /**
325
+ * Replace the stat name by their value using stat
326
+ * and after evaluate any formula using `replaceFormulaInDice`
327
+ * @param {string} originalDice
328
+ * @param {Record<string,number>|undefined} stats
329
+ * @param {number} minThreshold Minimum similarity threshold to consider a stat name match
330
+ * @param {string|undefined} dollarValue
331
+ */
332
+ declare function generateStatsDice(originalDice: string, stats?: Record<string, number>, minThreshold?: number, dollarValue?: string): string;
333
+ /**
334
+ * Replace the {{}} in the dice string and evaluate the interior if any
335
+ * @param dice {string}
336
+ */
337
+ declare function replaceFormulaInDice(dice: string): string;
338
+
339
+ type FormulaHintResult = {
340
+ kind: "resolved";
341
+ value: number;
342
+ } | {
343
+ kind: "error";
344
+ } | {
345
+ kind: "not-formula";
346
+ };
347
+ declare function resolveFormulaHint(formula: string, allAttributes: Record<string, number | string>, similarityThreshold?: number): FormulaHintResult;
348
+
323
349
  /**
324
350
  * Utility functions for string similarity and distance calculations.
325
351
  */
@@ -342,6 +368,18 @@ declare function findBestRecord(record: Record<string, string>, searchTerm: stri
342
368
  declare function replaceUnknown(dice: string, replacer: string): string;
343
369
  declare function verifyStatMatcherPattern(dice: string, replaceUnknow?: string): string;
344
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
+ };
345
383
  /**
346
384
  * Escape regex string
347
385
  * @param string {string}
@@ -353,20 +391,6 @@ declare function escapeRegex(string: string): string;
353
391
  * @return {string} the dice with the text in brackets as if, but the dice (not in brackets) is standardized
354
392
  */
355
393
  declare function standardizeDice(dice: string): string;
356
- /**
357
- * Replace the stat name by their value using stat
358
- * and after evaluate any formula using `replaceFormulaInDice`
359
- * @param {string} originalDice
360
- * @param {Record<string,number>|undefined} stats
361
- * @param {number} minThreshold Minimum similarity threshold to consider a stat name match
362
- * @param {string|undefined} dollarValue
363
- */
364
- declare function generateStatsDice(originalDice: string, stats?: Record<string, number>, minThreshold?: number, dollarValue?: string): string;
365
- /**
366
- * Replace the {{}} in the dice string and evaluate the interior if any
367
- * @param dice {string}
368
- */
369
- declare function replaceFormulaInDice(dice: string): string;
370
394
  /**
371
395
  * Verify if a value is a number, even if it's a "number" string
372
396
  * @param value {unknown}
@@ -466,4 +490,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
466
490
  */
467
491
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
468
492
 
469
- export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, 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, 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,14 +312,40 @@ 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;
321
322
  }, res: boolean, engine?: Engine | null, pity?: boolean): string;
322
323
 
324
+ /**
325
+ * Replace the stat name by their value using stat
326
+ * and after evaluate any formula using `replaceFormulaInDice`
327
+ * @param {string} originalDice
328
+ * @param {Record<string,number>|undefined} stats
329
+ * @param {number} minThreshold Minimum similarity threshold to consider a stat name match
330
+ * @param {string|undefined} dollarValue
331
+ */
332
+ declare function generateStatsDice(originalDice: string, stats?: Record<string, number>, minThreshold?: number, dollarValue?: string): string;
333
+ /**
334
+ * Replace the {{}} in the dice string and evaluate the interior if any
335
+ * @param dice {string}
336
+ */
337
+ declare function replaceFormulaInDice(dice: string): string;
338
+
339
+ type FormulaHintResult = {
340
+ kind: "resolved";
341
+ value: number;
342
+ } | {
343
+ kind: "error";
344
+ } | {
345
+ kind: "not-formula";
346
+ };
347
+ declare function resolveFormulaHint(formula: string, allAttributes: Record<string, number | string>, similarityThreshold?: number): FormulaHintResult;
348
+
323
349
  /**
324
350
  * Utility functions for string similarity and distance calculations.
325
351
  */
@@ -342,6 +368,18 @@ declare function findBestRecord(record: Record<string, string>, searchTerm: stri
342
368
  declare function replaceUnknown(dice: string, replacer: string): string;
343
369
  declare function verifyStatMatcherPattern(dice: string, replaceUnknow?: string): string;
344
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
+ };
345
383
  /**
346
384
  * Escape regex string
347
385
  * @param string {string}
@@ -353,20 +391,6 @@ declare function escapeRegex(string: string): string;
353
391
  * @return {string} the dice with the text in brackets as if, but the dice (not in brackets) is standardized
354
392
  */
355
393
  declare function standardizeDice(dice: string): string;
356
- /**
357
- * Replace the stat name by their value using stat
358
- * and after evaluate any formula using `replaceFormulaInDice`
359
- * @param {string} originalDice
360
- * @param {Record<string,number>|undefined} stats
361
- * @param {number} minThreshold Minimum similarity threshold to consider a stat name match
362
- * @param {string|undefined} dollarValue
363
- */
364
- declare function generateStatsDice(originalDice: string, stats?: Record<string, number>, minThreshold?: number, dollarValue?: string): string;
365
- /**
366
- * Replace the {{}} in the dice string and evaluate the interior if any
367
- * @param dice {string}
368
- */
369
- declare function replaceFormulaInDice(dice: string): string;
370
394
  /**
371
395
  * Verify if a value is a number, even if it's a "number" string
372
396
  * @param value {unknown}
@@ -466,4 +490,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
466
490
  */
467
491
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
468
492
 
469
- export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, 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, 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 };