@dicelette/core 1.23.1 → 1.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -2,29 +2,19 @@ import { Engine, Random } from 'random-js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  /**
5
- * Allow to replace the compare part of a dice and use the critical customized one
6
- * @example
7
- * dice = "1d20=20";
8
- * custom critical {sign: ">", value: "$/2"}
9
- * Random stats = 6
10
- * result = "1d20>3"
11
- */
12
- declare function createCriticalCustom(dice: string, customCritical: CustomCritical, template: StatisticalTemplate, engine?: Engine | null): string;
13
- /**
14
- * Parse the string provided and turn it as a readable dice for dice parser
15
- * @param dice {string}
16
- * @param engine
17
- * @param pity
5
+ * Utility function that allow to get the id of an engine
6
+ * @param engine {unknown} Engine to identify
7
+ * @returns {string} Id of the engine or "unknown"
8
+ * @private
18
9
  */
19
- declare function roll(dice: string, engine?: Engine | null, pity?: boolean): Resultat | undefined;
10
+ declare function getEngineId(engine: unknown): string;
20
11
  /**
21
- * Evaluate a formula and replace "^" by "**" if any
22
- * @param {Sign} sign
23
- * @param {number} value
24
- * @param {number} total
25
- * @returns
12
+ * Utility function to get the engine from its name
13
+ * @param engine {"nativeMath" | "browserCrypto" | "nodeCrypto"} The engine name
14
+ * @returns {Engine} The engine
15
+ * @public
26
16
  */
27
- declare function calculator(sign: Sign, value: number, total: number): number;
17
+ declare function getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine;
28
18
 
29
19
  declare class DiceTypeError extends Error {
30
20
  readonly dice: string;
@@ -87,6 +77,7 @@ interface Resultat {
87
77
  */
88
78
  total?: number;
89
79
  pityLogs?: number;
80
+ trivial?: boolean;
90
81
  }
91
82
  interface Compare {
92
83
  /**
@@ -240,6 +231,11 @@ interface CustomCritical {
240
231
  */
241
232
  affectSkill?: boolean;
242
233
  }
234
+ declare enum SortOrder {
235
+ Ascending = "sa",
236
+ Descending = "sd",
237
+ None = "none"
238
+ }
243
239
 
244
240
  declare const COMMENT_REGEX: RegExp;
245
241
  declare const SIGN_REGEX: RegExp;
@@ -297,6 +293,20 @@ declare const templateSchema: z.ZodObject<{
297
293
  damage: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
298
294
  }, z.core.$strip>;
299
295
 
296
+ /**
297
+ * Parse the string provided and turn it as a readable dice for dice parser
298
+ * @param {string} dice The dice string to parse and roll
299
+ * @param {Engine|null} engine The random engine to use, default to nodeCrypto
300
+ * @param {boolean} pity Whether to enable pity system (reroll on failure) or not
301
+ * @param {boolean} sort Whether to sort the dice results or not
302
+ * @returns {Resultat|undefined} The result of the roll
303
+ */
304
+ declare function roll(dice: string, engine?: Engine | null, pity?: boolean, sort?: SortOrder): Resultat | undefined;
305
+ declare function replaceInFormula(element: string, diceResult: Resultat, compareResult: {
306
+ dice: string;
307
+ compare: Compare | undefined;
308
+ }, res: boolean, engine?: Engine | null, pity?: boolean): string;
309
+
300
310
  /**
301
311
  * Escape regex string
302
312
  * @param string {string}
@@ -345,19 +355,14 @@ declare function replaceExpByRandom(dice: string, engine?: Engine | null): strin
345
355
  */
346
356
  declare function randomInt(min: number, max: number, engine?: Engine | null, rng?: Random): number;
347
357
  /**
348
- * Utility function that allow to get the id of an engine
349
- * @param engine {unknown} Engine to identify
350
- * @returns {string} Id of the engine or "unknown"
351
- * @private
352
- */
353
- declare function getEngineId(engine: unknown): string;
354
- /**
355
- * Utility function to get the engine from its name
356
- * @param engine {"nativeMath" | "browserCrypto" | "nodeCrypto"} The engine name
357
- * @returns {Engine} The engine
358
- * @public
358
+ * Allow to replace the compare part of a dice and use the critical customized one
359
+ * @example
360
+ * dice = "1d20=20";
361
+ * custom critical {sign: ">", value: "$/2"}
362
+ * Random stats = 6
363
+ * result = "1d20>3"
359
364
  */
360
- declare function getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine;
365
+ declare function createCriticalCustom(dice: string, customCritical: CustomCritical, template: StatisticalTemplate, engine?: Engine | null): string;
361
366
 
362
367
  /**
363
368
  * Verify if the provided dice work with random value
@@ -425,4 +430,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
425
430
  */
426
431
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
427
432
 
428
- export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, OPTIONAL_COMMENT, 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, getEngine, getEngineId, isNumber, randomInt, replaceExpByRandom, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
433
+ export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, OPTIONAL_COMMENT, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, getEngine, getEngineId, isNumber, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
package/dist/index.d.ts CHANGED
@@ -2,29 +2,19 @@ import { Engine, Random } from 'random-js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  /**
5
- * Allow to replace the compare part of a dice and use the critical customized one
6
- * @example
7
- * dice = "1d20=20";
8
- * custom critical {sign: ">", value: "$/2"}
9
- * Random stats = 6
10
- * result = "1d20>3"
11
- */
12
- declare function createCriticalCustom(dice: string, customCritical: CustomCritical, template: StatisticalTemplate, engine?: Engine | null): string;
13
- /**
14
- * Parse the string provided and turn it as a readable dice for dice parser
15
- * @param dice {string}
16
- * @param engine
17
- * @param pity
5
+ * Utility function that allow to get the id of an engine
6
+ * @param engine {unknown} Engine to identify
7
+ * @returns {string} Id of the engine or "unknown"
8
+ * @private
18
9
  */
19
- declare function roll(dice: string, engine?: Engine | null, pity?: boolean): Resultat | undefined;
10
+ declare function getEngineId(engine: unknown): string;
20
11
  /**
21
- * Evaluate a formula and replace "^" by "**" if any
22
- * @param {Sign} sign
23
- * @param {number} value
24
- * @param {number} total
25
- * @returns
12
+ * Utility function to get the engine from its name
13
+ * @param engine {"nativeMath" | "browserCrypto" | "nodeCrypto"} The engine name
14
+ * @returns {Engine} The engine
15
+ * @public
26
16
  */
27
- declare function calculator(sign: Sign, value: number, total: number): number;
17
+ declare function getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine;
28
18
 
29
19
  declare class DiceTypeError extends Error {
30
20
  readonly dice: string;
@@ -87,6 +77,7 @@ interface Resultat {
87
77
  */
88
78
  total?: number;
89
79
  pityLogs?: number;
80
+ trivial?: boolean;
90
81
  }
91
82
  interface Compare {
92
83
  /**
@@ -240,6 +231,11 @@ interface CustomCritical {
240
231
  */
241
232
  affectSkill?: boolean;
242
233
  }
234
+ declare enum SortOrder {
235
+ Ascending = "sa",
236
+ Descending = "sd",
237
+ None = "none"
238
+ }
243
239
 
244
240
  declare const COMMENT_REGEX: RegExp;
245
241
  declare const SIGN_REGEX: RegExp;
@@ -297,6 +293,20 @@ declare const templateSchema: z.ZodObject<{
297
293
  damage: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
298
294
  }, z.core.$strip>;
299
295
 
296
+ /**
297
+ * Parse the string provided and turn it as a readable dice for dice parser
298
+ * @param {string} dice The dice string to parse and roll
299
+ * @param {Engine|null} engine The random engine to use, default to nodeCrypto
300
+ * @param {boolean} pity Whether to enable pity system (reroll on failure) or not
301
+ * @param {boolean} sort Whether to sort the dice results or not
302
+ * @returns {Resultat|undefined} The result of the roll
303
+ */
304
+ declare function roll(dice: string, engine?: Engine | null, pity?: boolean, sort?: SortOrder): Resultat | undefined;
305
+ declare function replaceInFormula(element: string, diceResult: Resultat, compareResult: {
306
+ dice: string;
307
+ compare: Compare | undefined;
308
+ }, res: boolean, engine?: Engine | null, pity?: boolean): string;
309
+
300
310
  /**
301
311
  * Escape regex string
302
312
  * @param string {string}
@@ -345,19 +355,14 @@ declare function replaceExpByRandom(dice: string, engine?: Engine | null): strin
345
355
  */
346
356
  declare function randomInt(min: number, max: number, engine?: Engine | null, rng?: Random): number;
347
357
  /**
348
- * Utility function that allow to get the id of an engine
349
- * @param engine {unknown} Engine to identify
350
- * @returns {string} Id of the engine or "unknown"
351
- * @private
352
- */
353
- declare function getEngineId(engine: unknown): string;
354
- /**
355
- * Utility function to get the engine from its name
356
- * @param engine {"nativeMath" | "browserCrypto" | "nodeCrypto"} The engine name
357
- * @returns {Engine} The engine
358
- * @public
358
+ * Allow to replace the compare part of a dice and use the critical customized one
359
+ * @example
360
+ * dice = "1d20=20";
361
+ * custom critical {sign: ">", value: "$/2"}
362
+ * Random stats = 6
363
+ * result = "1d20>3"
359
364
  */
360
- declare function getEngine(engine: "nativeMath" | "browserCrypto" | "nodeCrypto"): Engine;
365
+ declare function createCriticalCustom(dice: string, customCritical: CustomCritical, template: StatisticalTemplate, engine?: Engine | null): string;
361
366
 
362
367
  /**
363
368
  * Verify if the provided dice work with random value
@@ -425,4 +430,4 @@ declare function testStatCombinaison(template: StatisticalTemplate, engine?: Eng
425
430
  */
426
431
  declare function generateRandomStat(total?: number | undefined, max?: number, min?: number, engine?: Engine | null): number;
427
432
 
428
- export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, OPTIONAL_COMMENT, 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, getEngine, getEngineId, isNumber, randomInt, replaceExpByRandom, replaceFormulaInDice, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };
433
+ export { COMMENT_REGEX, type Compare, type ComparedValue, type Critical, type CustomCritical, type CustomCriticalMap, DETECT_CRITICAL, DiceTypeError, EmptyObjectError, FormulaError, MaxGreater, type Modifier, NoStatisticsError, OPTIONAL_COMMENT, type Resultat, SIGN_REGEX, SIGN_REGEX_SPACE, SYMBOL_DICE, type Sign, SortOrder, type Statistic, type StatisticalSchema, type StatisticalTemplate, TooManyDice, TooManyStats, createCriticalCustom, diceRandomParse, diceTypeRandomParse, escapeRegex, evalCombinaison, evalOneCombinaison, evalStatsDice, generateRandomStat, generateStatsDice, getEngine, getEngineId, isNumber, randomInt, replaceExpByRandom, replaceFormulaInDice, replaceInFormula, roll, standardizeDice, templateSchema, testDiceRegistered, testStatCombinaison, verifyTemplateValue };