@platonic-dice/core 2.1.2 → 3.0.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.
Files changed (66) hide show
  1. package/README.md +11 -2
  2. package/dist/analyseModTest.js +12 -10
  3. package/dist/analyseTest.js +43 -11
  4. package/dist/entities/DiceTestConditions.js +174 -0
  5. package/dist/entities/ModifiedTestConditions.js +30 -41
  6. package/dist/entities/RollModifier.js +15 -1
  7. package/dist/entities/TestConditions.js +26 -182
  8. package/dist/entities/TestConditionsArray.js +87 -0
  9. package/dist/entities/index.js +250 -39
  10. package/dist/index.js +42 -25
  11. package/dist/rollDiceMod.js +30 -17
  12. package/dist/rollDiceTest.js +68 -0
  13. package/dist/rollMod.js +3 -4
  14. package/dist/rollModTest.js +40 -13
  15. package/dist/rollTest.js +50 -15
  16. package/dist/utils/determineOutcome.js +35 -7
  17. package/dist/utils/getArrayEvaluator.js +48 -0
  18. package/dist/utils/getEvaluator.js +84 -0
  19. package/dist/utils/index.js +244 -16
  20. package/dist/utils/outcomeMapper.js +62 -15
  21. package/dist/utils/testRegistry.js +91 -0
  22. package/dist/utils/testValidators.js +190 -0
  23. package/package.json +15 -17
  24. package/dist/analyseModTest.d.ts +0 -126
  25. package/dist/analyseModTest.d.ts.map +0 -1
  26. package/dist/analyseTest.d.ts +0 -101
  27. package/dist/analyseTest.d.ts.map +0 -1
  28. package/dist/entities/DieType.d.ts +0 -35
  29. package/dist/entities/DieType.d.ts.map +0 -1
  30. package/dist/entities/ModifiedTestConditions.d.ts +0 -89
  31. package/dist/entities/ModifiedTestConditions.d.ts.map +0 -1
  32. package/dist/entities/Outcome.d.ts +0 -26
  33. package/dist/entities/Outcome.d.ts.map +0 -1
  34. package/dist/entities/RollModifier.d.ts +0 -115
  35. package/dist/entities/RollModifier.d.ts.map +0 -1
  36. package/dist/entities/RollType.d.ts +0 -24
  37. package/dist/entities/RollType.d.ts.map +0 -1
  38. package/dist/entities/TestConditions.d.ts +0 -97
  39. package/dist/entities/TestConditions.d.ts.map +0 -1
  40. package/dist/entities/TestType.d.ts +0 -28
  41. package/dist/entities/TestType.d.ts.map +0 -1
  42. package/dist/entities/index.d.ts +0 -19
  43. package/dist/entities/index.d.ts.map +0 -1
  44. package/dist/index.d.ts +0 -5
  45. package/dist/index.d.ts.map +0 -1
  46. package/dist/roll.d.ts +0 -66
  47. package/dist/roll.d.ts.map +0 -1
  48. package/dist/rollDice.d.ts +0 -48
  49. package/dist/rollDice.d.ts.map +0 -1
  50. package/dist/rollDiceMod.d.ts +0 -54
  51. package/dist/rollDiceMod.d.ts.map +0 -1
  52. package/dist/rollMod.d.ts +0 -52
  53. package/dist/rollMod.d.ts.map +0 -1
  54. package/dist/rollModTest.d.ts +0 -72
  55. package/dist/rollModTest.d.ts.map +0 -1
  56. package/dist/rollTest.d.ts +0 -59
  57. package/dist/rollTest.d.ts.map +0 -1
  58. package/dist/utils/determineOutcome.d.ts +0 -45
  59. package/dist/utils/determineOutcome.d.ts.map +0 -1
  60. package/dist/utils/generateResult.d.ts +0 -30
  61. package/dist/utils/generateResult.d.ts.map +0 -1
  62. package/dist/utils/index.d.ts +0 -8
  63. package/dist/utils/index.d.ts.map +0 -1
  64. package/dist/utils/outcomeMapper.d.ts +0 -29
  65. package/dist/utils/outcomeMapper.d.ts.map +0 -1
  66. package/dist-types.d.ts +0 -70
@@ -1,97 +0,0 @@
1
- export type BaseTestCondition = {
2
- dieType: DieTypeValue;
3
- };
4
- export type TargetConditions = BaseTestCondition & {
5
- target: number;
6
- };
7
- export type WithinConditions = BaseTestCondition & {
8
- min: number;
9
- max: number;
10
- };
11
- export type SpecificListConditions = BaseTestCondition & {
12
- values: number[];
13
- };
14
- export type SkillConditions = BaseTestCondition & {
15
- target: number;
16
- critical_success?: number;
17
- critical_failure?: number;
18
- };
19
- export type TestTypeValue = import("./TestType").TestTypeValue;
20
- export type DieTypeValue = import("./DieType").DieTypeValue;
21
- /**
22
- * Represents any valid dice roll test condition.
23
- *
24
- * This is a union type of all the internal test condition shapes:
25
- * - `TargetConditions` – single target value
26
- * - `SkillConditions` – target with optional critical thresholds
27
- * - `WithinConditions` – min/max range
28
- * - `SpecificListConditions` – array of specific allowed values
29
- */
30
- export type Conditions = TargetConditions | SkillConditions | WithinConditions | SpecificListConditions;
31
- export type TestConditionsInstance = InstanceType<typeof TestConditions>;
32
- /**
33
- * @typedef {import("./TestType").TestTypeValue} TestTypeValue
34
- * @typedef {import("./DieType").DieTypeValue} DieTypeValue
35
- */
36
- /**
37
- * Represents a set of conditions for a dice roll test.
38
- */
39
- export class TestConditions {
40
- /**
41
- * @param {TestTypeValue} testType - The test type.
42
- * @param {Conditions} conditions - The test conditions object.
43
- * @param {DieTypeValue} dieType - The die type to validate numeric ranges.
44
- * @throws {TypeError|RangeError} If the test type or conditions are invalid.
45
- */
46
- constructor(testType: TestTypeValue, conditions: Conditions, dieType: DieTypeValue);
47
- /** @type {TestTypeValue} */
48
- testType: TestTypeValue;
49
- /** @type {Conditions} */
50
- conditions: Conditions;
51
- /** @type {DieTypeValue} */
52
- dieType: DieTypeValue;
53
- /**
54
- * Validates that the test conditions still conforms to spec.
55
- * (Useful if they are loaded dynamically or serialized.)
56
- * @throws {TypeError} If the test conditions are invalid.
57
- */
58
- validate(): void;
59
- }
60
- /**
61
- * Master validation function for all test conditions.
62
- *
63
- * @function areValidTestConditions
64
- * @param {Conditions} c
65
- * @param {TestTypeValue} testType
66
- * @returns {boolean}
67
- */
68
- export function areValidTestConditions(c: Conditions, testType: TestTypeValue): boolean;
69
- /**
70
- * Normalises any input into a {@link TestConditions} instance.
71
- * Supports both pre-existing instances and plain objects.
72
- * Automatically validates all conditions for the specified die type.
73
- *
74
- * @function normaliseTestConditions
75
- * @param {TestConditions | { testType: TestTypeValue, [key: string]: any }} tc
76
- * A {@link TestConditions} instance or plain object with `testType` and other fields.
77
- * @param {DieTypeValue} dieType
78
- * The die type (e.g., `'d6'`, `'d20'`) used for validation.
79
- * @returns {TestConditions}
80
- * A validated {@link TestConditions} instance.
81
- * @throws {TypeError}
82
- * If the input is neither a TestConditions instance nor a plain object.
83
- *
84
- * @example
85
- * // Passing a plain object
86
- * const conditions = normaliseTestConditions({ testType: 'atLeast', target: 4 }, 'd6');
87
- *
88
- * @example
89
- * // Passing an existing TestConditions instance
90
- * const existing = new TestConditions('exact', { target: 3 }, 'd6');
91
- * const conditions2 = normaliseTestConditions(existing, 'd6');
92
- */
93
- export function normaliseTestConditions(tc: TestConditions | {
94
- testType: TestTypeValue;
95
- [key: string]: any;
96
- }, dieType: DieTypeValue): TestConditions;
97
- //# sourceMappingURL=TestConditions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TestConditions.d.ts","sourceRoot":"","sources":["../../src/entities/TestConditions.js"],"names":[],"mappings":";aAiMc,YAAY;;+BAKb,iBAAiB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;+BAEtC,iBAAiB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE;qCAEhD,iBAAiB,GAAG;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE;8BAExC,iBAAiB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE;4BA5L5F,OAAO,YAAY,EAAE,aAAa;2BAClC,OAAO,WAAW,EAAE,YAAY;;;;;;;;;;yBA4JhC,gBAAgB,GAAG,eAAe,GAAG,gBAAgB,GAAG,sBAAsB;qCAI9E,YAAY,CAAC,OAAO,cAAc,CAAC;AAlKhD;;;GAGG;AAEH;;GAEG;AACH;IACE;;;;;OAKG;IACH,sBALW,aAAa,cACb,UAAU,WACV,YAAY,EAgDtB;IANC,4BAA4B;IAC5B,UADW,aAAa,CACA;IACxB,yBAAyB;IACzB,YADW,UAAU,CACO;IAC5B,2BAA2B;IAC3B,SADW,YAAY,CACD;IAGxB;;;;OAIG;IACH,iBASC;CACF;AAED;;;;;;;GAOG;AACH,0CAJW,UAAU,YACV,aAAa,GACX,OAAO,CAwBnB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,4CAlBW,cAAc,GAAG;IAAE,QAAQ,EAAE,aAAa,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,WAEhE,YAAY,GAEV,cAAc,CA0B1B"}
@@ -1,28 +0,0 @@
1
- export type TestTypeKey = keyof typeof TestType;
2
- export type TestTypeValue = (typeof TestType)[keyof typeof TestType];
3
- export type TestType = string;
4
- /**
5
- * @module @platonic-dice/core/src/entities/TestType
6
- * @description
7
- * Enum for test evaluation types (used in {@link TestConditions}).
8
- *
9
- * @readonly
10
- * @enum {string}
11
- */
12
- export const TestType: Readonly<{
13
- Exact: "exact";
14
- AtLeast: "at_least";
15
- AtMost: "at_most";
16
- Within: "within";
17
- InList: "in_list";
18
- Skill: "skill";
19
- }>;
20
- /**
21
- * Checks whether a given value is a valid `TestType`.
22
- *
23
- * @function isValidTestType
24
- * @param {TestTypeValue | null | undefined} testType
25
- * @returns {boolean}
26
- */
27
- export function isValidTestType(testType: TestTypeValue | null | undefined): boolean;
28
- //# sourceMappingURL=TestType.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TestType.d.ts","sourceRoot":"","sources":["../../src/entities/TestType.js"],"names":[],"mappings":"0BA+Ba,MAAM,OAAO,QAAQ;4BACrB,CAAA,OAAO,QAAQ,EAAC,MAAM,OAAO,QAAQ,CAAC;uBAzBzC,MAAM;AANhB;;;;;;;GAOG;AACH;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,0CAHW,aAAa,GAAG,IAAI,GAAG,SAAS,GAC9B,OAAO,CAKnB"}
@@ -1,19 +0,0 @@
1
- import { DieType } from "./DieType.js";
2
- import { isValidDieType } from "./DieType.js";
3
- import { Outcome } from "./Outcome.js";
4
- import { isValidOutcome } from "./Outcome.js";
5
- import { RollModifier } from "./RollModifier.js";
6
- import { isValidRollModifier } from "./RollModifier.js";
7
- import { normaliseRollModifier } from "./RollModifier.js";
8
- import { RollType } from "./RollType.js";
9
- import { isValidRollType } from "./RollType.js";
10
- import { TestConditions } from "./TestConditions.js";
11
- import { areValidTestConditions } from "./TestConditions.js";
12
- import { normaliseTestConditions } from "./TestConditions.js";
13
- import { ModifiedTestConditions } from "./ModifiedTestConditions.js";
14
- import { areValidModifiedTestConditions } from "./ModifiedTestConditions.js";
15
- import { computeModifiedRange } from "./ModifiedTestConditions.js";
16
- import { TestType } from "./TestType.js";
17
- import { isValidTestType } from "./TestType.js";
18
- export { DieType, isValidDieType, Outcome, isValidOutcome, RollModifier, isValidRollModifier, normaliseRollModifier, RollType, isValidRollType, TestConditions, areValidTestConditions, normaliseTestConditions, ModifiedTestConditions, areValidModifiedTestConditions, computeModifiedRange, TestType, isValidTestType };
19
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.js"],"names":[],"mappings":""}
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare const _exports: typeof import("./roll") & typeof import("./rollDice") & typeof import("./rollMod") & typeof import("./rollDiceMod") & typeof import("./rollTest") & typeof import("./rollModTest") & typeof import("./analyseTest") & typeof import("./analyseModTest") & typeof import("./entities") & {
2
- default: any;
3
- };
4
- export = _exports;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"wBAyBU,cAAc,QAAQ,CAAC,GAChC,cAAuB,YAAY,CAAC,GACpC,cAAuB,WAAW,CAAC,GACnC,cAAuB,eAAe,CAAC,GACvC,cAAuB,YAAY,CAAC,GACpC,cAAuB,eAAe,CAAC,GACvC,cAAuB,eAAe,CAAC,GACvC,cAAuB,kBAAkB,CAAC,GAC1C,cAAuB,YAAY,CAAC,GACpC;IAAW,OAAO,EAAE,GAAG,CAAA;CAAE"}
package/dist/roll.d.ts DELETED
@@ -1,66 +0,0 @@
1
- export type DieTypeValue = import("./entities/DieType").DieTypeValue;
2
- export type RollTypeValue = import("./entities/RollType").RollTypeValue;
3
- /**
4
- * @typedef {import("./entities/DieType").DieTypeValue} DieTypeValue
5
- * @typedef {import("./entities/RollType").RollTypeValue} RollTypeValue
6
- */
7
- /**
8
- * Rolls a single die of the specified type, optionally applying advantage or disadvantage.
9
- *
10
- * @function roll
11
- * @param {DieTypeValue} dieType - The type of die to roll (e.g., `DieType.D20`).
12
- * @param {RollTypeValue | undefined} [rollType=undefined] - Optional roll mode (`RollType.Advantage` or `RollType.Disadvantage`).
13
- * @returns {number} The rolled value (integer between 1 and the die's maximum face).
14
- * @throws {TypeError} If `dieType` or `rollType` are invalid.
15
- *
16
- * @example
17
- * const result = roll(DieType.D20, RollType.Advantage);
18
- */
19
- export function roll(dieType: DieTypeValue, rollType?: RollTypeValue | undefined): number;
20
- /**
21
- * Rolls a die with advantage.
22
- * @type {(dieType: DieTypeValue) => number}
23
- *
24
- * @example
25
- * const result = rollAdv(DieType.D10);
26
- */
27
- export const rollAdv: (dieType: DieTypeValue) => number;
28
- /**
29
- * Rolls a die with disadvantage.
30
- * @type {(dieType: DieTypeValue) => number}
31
- *
32
- * @example
33
- * const result = rollDis(DieType.D10);
34
- */
35
- export const rollDis: (dieType: DieTypeValue) => number;
36
- /**
37
- * Rolls a D4 die.
38
- * @type {(rollType?: RollTypeValue | undefined) => number}
39
- */
40
- export const rollD4: (rollType?: RollTypeValue | undefined) => number;
41
- /**
42
- * Rolls a D6 die.
43
- * @type {(rollType?: RollTypeValue | undefined) => number}
44
- */
45
- export const rollD6: (rollType?: RollTypeValue | undefined) => number;
46
- /**
47
- * Rolls a D8 die.
48
- * @type {(rollType?: RollTypeValue | undefined) => number}
49
- */
50
- export const rollD8: (rollType?: RollTypeValue | undefined) => number;
51
- /**
52
- * Rolls a D10 die.
53
- * @type {(rollType?: RollTypeValue | undefined) => number}
54
- */
55
- export const rollD10: (rollType?: RollTypeValue | undefined) => number;
56
- /**
57
- * Rolls a D12 die.
58
- * @type {(rollType?: RollTypeValue | undefined) => number}
59
- */
60
- export const rollD12: (rollType?: RollTypeValue | undefined) => number;
61
- /**
62
- * Rolls a D20 die.
63
- * @type {(rollType?: RollTypeValue | undefined) => number}
64
- */
65
- export const rollD20: (rollType?: RollTypeValue | undefined) => number;
66
- //# sourceMappingURL=roll.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"roll.d.ts","sourceRoot":"","sources":["../src/roll.js"],"names":[],"mappings":"2BA8Ba,OAAO,oBAAoB,EAAE,YAAY;4BACzC,OAAO,qBAAqB,EAAE,aAAa;AAFxD;;;GAGG;AAEH;;;;;;;;;;;GAWG;AACH,8BARW,YAAY,aACZ,aAAa,GAAG,SAAS,GACvB,MAAM,CAwBlB;AAMD;;;;;;GAMG;AACH,sBALU,CAAC,OAAO,EAAE,YAAY,KAAK,MAAM,CAKoB;AAE/D;;;;;;GAMG;AACH,sBALU,CAAC,OAAO,EAAE,YAAY,KAAK,MAAM,CAKuB;AAElE;;;GAGG;AACH,qBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEU;AAEpE;;;GAGG;AACH,qBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEU;AAEpE;;;GAGG;AACH,qBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEU;AAEpE;;;GAGG;AACH,sBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEY;AAEtE;;;GAGG;AACH,sBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEY;AAEtE;;;GAGG;AACH,sBAFU,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM,CAEY"}
@@ -1,48 +0,0 @@
1
- declare namespace _exports {
2
- export { DieTypeValue, RollDiceAlias };
3
- }
4
- declare namespace _exports {
5
- export { rollDice };
6
- }
7
- export = _exports;
8
- type DieTypeValue = import("./entities/DieType").DieTypeValue;
9
- type RollDiceAlias = (dieType: import("./entities/DieType").DieTypeValue) => {
10
- array: number[];
11
- sum: number;
12
- };
13
- /**
14
- * @typedef {import("./entities/DieType").DieTypeValue} DieTypeValue
15
- */
16
- /**
17
- * Rolls one or more dice of the specified type.
18
- *
19
- * @function rollDice
20
- * @param {DieTypeValue} dieType - The type of die to roll (e.g., `DieType.D6`, `DieType.D20`).
21
- * @param {Object} [options] - Optional configuration.
22
- * @param {number} [options.count=1] - Number of dice to roll. Must be a positive integer.
23
- * @returns {{ array: number[], sum: number }} An object containing:
24
- * - `array`: an array of individual die rolls.
25
- * - `sum`: the total sum of all rolls.
26
- * @throws {TypeError} If `dieType` is invalid.
27
- * @throws {TypeError} If `count` is not a positive integer.
28
- *
29
- * @example
30
- * const result = rollDice(DieType.D6, { count: 5 });
31
- * console.log(result.sum); // e.g., 18
32
- * console.log(result.array); // e.g., [2, 5, 3, 1, 7]
33
- *
34
- * @example
35
- * // Roll a single d20
36
- * const result = rollDice(DieType.D20);
37
- *
38
- * @example
39
- * // Roll 3d6
40
- * const result = rollDice(DieType.D6, { count: 3 });
41
- */
42
- declare function rollDice(dieType: DieTypeValue, { count }?: {
43
- count?: number | undefined;
44
- }): {
45
- array: number[];
46
- sum: number;
47
- };
48
- //# sourceMappingURL=rollDice.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rollDice.d.ts","sourceRoot":"","sources":["../src/rollDice.js"],"names":[],"mappings":";;;;;;;oBAsBa,OAAO,oBAAoB,EAAE,YAAY;qBAmDzC,CAAC,OAAO,EAAE,OAAO,oBAAoB,EAAE,YAAY,KAAK;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE;AApDrG;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,mCAtBW,YAAY,cAEpB;IAAyB,KAAK;CAC9B,GAAU;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAoC5C"}
@@ -1,54 +0,0 @@
1
- export type DieTypeValue = import("./entities/DieType").DieTypeValue;
2
- export type RollModifierFunction = import("./entities/RollModifier").RollModifierFunction;
3
- export type RollModifierInstance = import("./entities/RollModifier").RollModifierInstance;
4
- export type DiceModifier = import("./entities/RollModifier").DiceModifier;
5
- export type rollDiceModModifier = RollModifierInstance | RollModifierFunction | DiceModifier;
6
- /**
7
- * @typedef {import("./entities/DieType").DieTypeValue} DieTypeValue
8
- * @typedef {import("./entities/RollModifier").RollModifierFunction} RollModifierFunction
9
- * @typedef {import("./entities/RollModifier").RollModifierInstance} RollModifierInstance
10
- * @typedef {import("./entities/RollModifier").DiceModifier} DiceModifier
11
- */
12
- /**
13
- * @typedef {RollModifierInstance | RollModifierFunction | DiceModifier} rollDiceModModifier
14
- */
15
- /**
16
- * Rolls multiple dice with optional per-die (`each`) and net (`net`) modifiers.
17
- *
18
- * @function rollDiceMod
19
- * @param {DieTypeValue} dieType - The die type (e.g., `DieType.D6`).
20
- * @param {rollDiceModModifier} [modifier={}] - The modifier(s) to apply.
21
- * @param {{ count?: number }} [options={}] - Optional roll count (default: 1).
22
- * @returns {{
23
- * base: { array: number[], sum: number },
24
- * modified: { each: { array: number[], sum: number }, net: { value: number } }
25
- * }}
26
- * @throws {TypeError} If `count` is invalid.
27
- * @throws {TypeError} If any modifier is invalid.
28
- */
29
- export function rollDiceMod(dieType: DieTypeValue, modifier?: rollDiceModModifier, { count }?: {
30
- count?: number;
31
- }): {
32
- base: {
33
- array: number[];
34
- sum: number;
35
- };
36
- modified: {
37
- each: {
38
- array: number[];
39
- sum: number;
40
- };
41
- net: {
42
- value: number;
43
- };
44
- };
45
- };
46
- /** @type {(dieType: DieTypeValue, modifier?: rollDiceModModifier, options?: { count?: number }) => number[]} */
47
- export const rollDiceModArr: (dieType: DieTypeValue, modifier?: rollDiceModModifier, options?: {
48
- count?: number;
49
- }) => number[];
50
- /** @type {(dieType: DieTypeValue, modifier?: rollDiceModModifier, options?: { count?: number }) => number} */
51
- export const rollDiceModNet: (dieType: DieTypeValue, modifier?: rollDiceModModifier, options?: {
52
- count?: number;
53
- }) => number;
54
- //# sourceMappingURL=rollDiceMod.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rollDiceMod.d.ts","sourceRoot":"","sources":["../src/rollDiceMod.js"],"names":[],"mappings":"2BAgCa,OAAO,oBAAoB,EAAE,YAAY;mCACzC,OAAO,yBAAyB,EAAE,oBAAoB;mCACtD,OAAO,yBAAyB,EAAE,oBAAoB;2BACtD,OAAO,yBAAyB,EAAE,YAAY;kCAI9C,oBAAoB,GAAG,oBAAoB,GAAG,YAAY;AARvE;;;;;GAKG;AAEH;;GAEG;AAEH;;;;;;;;;;;;;GAaG;AACH,qCAVW,YAAY,aACZ,mBAAmB,cACnB;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAChB;IACR,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,QAAQ,EAAE;QAAE,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,EAAE,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,GAAG,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAA;CAC7E,CA4CH;AA8BD,gHAAgH;AAChH,6BADW,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,KAAK,MAAM,EAAE,CAClE;AAE1C,8GAA8G;AAC9G,6BADW,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,KAAK,MAAM,CACtE"}
package/dist/rollMod.d.ts DELETED
@@ -1,52 +0,0 @@
1
- declare namespace _exports {
2
- export { DieTypeValue, RollTypeValue, RollModifierFunction, RollModifierInstance, DieModifierAlias };
3
- }
4
- declare namespace _exports {
5
- export { rollMod };
6
- }
7
- export = _exports;
8
- type DieTypeValue = import("./entities/DieType").DieTypeValue;
9
- type RollTypeValue = import("./entities/RollType").RollTypeValue;
10
- type RollModifierFunction = import("./entities/RollModifier").RollModifierFunction;
11
- type RollModifierInstance = import("./entities/RollModifier").RollModifierInstance;
12
- type DieModifierAlias = (rollType?: RollTypeValue | undefined) => number;
13
- /**
14
- * @typedef {import("./entities/DieType").DieTypeValue} DieTypeValue
15
- * @typedef {import("./entities/RollType").RollTypeValue} RollTypeValue
16
- * @typedef {import("./entities/RollModifier").RollModifierFunction} RollModifierFunction
17
- * @typedef {import("./entities/RollModifier").RollModifierInstance} RollModifierInstance
18
- */
19
- /**
20
- * Rolls a single modified die by applying a modifier function or RollModifier.
21
- *
22
- * This function first rolls a base value using {@link roll}, then applies
23
- * the provided modifier — either a function `(n) => number` or a
24
- * {@link RollModifier} instance — to produce the final result.
25
- *
26
- * @function rollMod
27
- * @param {DieTypeValue} dieType - The type of die to roll (e.g., `DieType.D20`).
28
- * @param {RollModifierFunction|RollModifierInstance} modifier - The modifier to apply.
29
- * Can be either:
30
- * - A RollModifierFunction `(n: number) => number`
31
- * - A {@link RollModifier} instance
32
- * @param {RollTypeValue | undefined} [rollType=undefined] - Optional roll mode (`RollType.Advantage` or `RollType.Disadvantage`).
33
- * @returns {{ base: number, modified: number }} - The unmodified roll (`base`) and the modified result (`modified`).
34
- * @throws {TypeError} If the modifier is invalid (not a function or RollModifier).
35
- * @throws {TypeError} If the `dieType` or `rollType` are invalid (delegated to {@link roll}).
36
- *
37
- * @example
38
- * const result = rollMod(DieType.D20, (n) => n + 2);
39
- * console.log(result); // { base: 14, modified: 16 }
40
- *
41
- * @example
42
- * const bonus = new RollModifier((n) => Math.min(n + 3, 20));
43
- * const result = rollMod(DieType.D20, bonus);
44
- *
45
- * @example
46
- * const result = rollMod(DieType.D10, (n) => Math.floor(n / 2), RollType.Advantage);
47
- */
48
- declare function rollMod(dieType: DieTypeValue, modifier: RollModifierFunction | RollModifierInstance, rollType?: RollTypeValue | undefined): {
49
- base: number;
50
- modified: number;
51
- };
52
- //# sourceMappingURL=rollMod.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rollMod.d.ts","sourceRoot":"","sources":["../src/rollMod.js"],"names":[],"mappings":";;;;;;;oBAuBa,OAAO,oBAAoB,EAAE,YAAY;qBACzC,OAAO,qBAAqB,EAAE,aAAa;4BAC3C,OAAO,yBAAyB,EAAE,oBAAoB;4BACtD,OAAO,yBAAyB,EAAE,oBAAoB;wBA8CtD,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,KAAK,MAAM;AAlD7D;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,kCArBW,YAAY,YACZ,oBAAoB,GAAC,oBAAoB,aAIzC,aAAa,GAAG,SAAS,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAsB9C"}
@@ -1,72 +0,0 @@
1
- export type DieTypeValue = import("./entities/DieType").DieTypeValue;
2
- export type OutcomeValue = import("./entities/Outcome").OutcomeValue;
3
- export type RollTypeValue = import("./entities/RollType").RollTypeValue;
4
- export type RollModifierFunction = import("./entities/RollModifier").RollModifierFunction;
5
- export type RollModifierInstance = import("./entities/RollModifier").RollModifierInstance;
6
- export type TestTypeValue = import("./entities/TestType").TestTypeValue;
7
- export type TestConditionsInstance = import("./entities/TestConditions").TestConditionsInstance;
8
- /**
9
- * Rolls a die with a modifier and evaluates the modified result against test conditions.
10
- *
11
- * @function rollModTest
12
- * @param {DieTypeValue} dieType - The type of die to roll (e.g., `DieType.D20`).
13
- * @param {RollModifierFunction|RollModifierInstance} modifier - The modifier to apply to the roll.
14
- * Can be either:
15
- * - A function `(n: number) => number`
16
- * - A {@link RollModifier} instance
17
- * @param {TestConditionsInstance|{ testType: TestTypeValue, [key: string]: any }} testConditions
18
- * Can be:
19
- * - A `TestConditions` instance
20
- * - A plain object `{ testType, ...conditions }`
21
- * @param {RollTypeValue} [rollType=undefined] - Optional roll mode (`RollType.Advantage` or `RollType.Disadvantage`).
22
- * @param {Object} [options={}] - Optional configuration.
23
- * @param {boolean} [options.useNaturalCrits] - If true, natural max/min rolls on the die trigger
24
- * critical success/failure (for Skill tests) or success/failure (for other test types).
25
- * If undefined, defaults to true for Skill test type and false for all others.
26
- * @returns {{ base: number, modified: number, outcome: OutcomeValue }}
27
- * - `base`: The raw die roll
28
- * - `modified`: The roll after applying the modifier
29
- * - `outcome`: The success/failure result based on test conditions
30
- * @throws {TypeError} If `dieType`, `modifier`, or `testConditions` are invalid.
31
- *
32
- * @example
33
- * const result = rollModTest(
34
- * DieType.D20,
35
- * (n) => n + 2,
36
- * { testType: TestType.AtLeast, target: 15 }
37
- * );
38
- * console.log(result); // { base: 14, modified: 16, outcome: "success" }
39
- *
40
- * @example
41
- * // With natural crits enabled (TTRPG style)
42
- * const result = rollModTest(
43
- * DieType.D20,
44
- * (n) => n + 5,
45
- * { testType: TestType.Skill, target: 15, critical_success: 25, critical_failure: 2 },
46
- * undefined,
47
- * { useNaturalCrits: true }
48
- * );
49
- * // If base roll is 20, outcome is always "critical_success"
50
- * // If base roll is 1, outcome is always "critical_failure"
51
- *
52
- * @example
53
- * // With advantage - compares outcomes, not just base rolls
54
- * const result = rollModTest(
55
- * DieType.D20,
56
- * (n) => n + 3,
57
- * { testType: TestType.Skill, target: 12, critical_success: 20, critical_failure: 1 },
58
- * RollType.Advantage
59
- * );
60
- * // Rolls twice, returns the result with the better outcome
61
- */
62
- export function rollModTest(dieType: DieTypeValue, modifier: RollModifierFunction | RollModifierInstance, testConditions: TestConditionsInstance | {
63
- testType: TestTypeValue;
64
- [key: string]: any;
65
- }, rollType?: RollTypeValue, options?: {
66
- useNaturalCrits?: boolean | undefined;
67
- }): {
68
- base: number;
69
- modified: number;
70
- outcome: OutcomeValue;
71
- };
72
- //# sourceMappingURL=rollModTest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rollModTest.d.ts","sourceRoot":"","sources":["../src/rollModTest.js"],"names":[],"mappings":"2BAoCa,OAAO,oBAAoB,EAAE,YAAY;2BACzC,OAAO,oBAAoB,EAAE,YAAY;4BACzC,OAAO,qBAAqB,EAAE,aAAa;mCAC3C,OAAO,yBAAyB,EAAE,oBAAoB;mCACtD,OAAO,yBAAyB,EAAE,oBAAoB;4BACtD,OAAO,qBAAqB,EAAE,aAAa;qCAC3C,OAAO,2BAA2B,EAAE,sBAAsB;AAyBvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,qCAlDW,YAAY,YACZ,oBAAoB,GAAC,oBAAoB,kBAIzC,sBAAsB,GAAC;IAAE,QAAQ,EAAE,aAAa,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,aAItE,aAAa,YAErB;IAA0B,eAAe;CAGzC,GAAU;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAsHrE"}
@@ -1,59 +0,0 @@
1
- declare namespace _exports {
2
- export { DieTypeValue, OutcomeValue, RollTypeValue, TestTypeValue, TestConditionsInstance, RollTestOptions };
3
- }
4
- declare namespace _exports {
5
- export { rollTest };
6
- }
7
- export = _exports;
8
- type DieTypeValue = import("./entities/DieType").DieTypeValue;
9
- type OutcomeValue = import("./entities/Outcome").OutcomeValue;
10
- type RollTypeValue = import("./entities/RollType").RollTypeValue;
11
- type TestTypeValue = import("./entities/TestType").TestTypeValue;
12
- type TestConditionsInstance = import("./entities/TestConditions").TestConditionsInstance;
13
- type RollTestOptions = {
14
- /**
15
- * - If true, rolling the die's maximum value
16
- * triggers CriticalSuccess (for Skill tests) or Success (for AtLeast/AtMost tests),
17
- * and rolling 1 triggers CriticalFailure (for Skill tests) or Failure (for AtLeast)
18
- * or Success (for AtMost). If undefined, defaults to true for TestType.Skill
19
- * and false for all other test types.
20
- */
21
- useNaturalCrits?: boolean | undefined;
22
- };
23
- /**
24
- * @typedef {import("./entities/DieType").DieTypeValue} DieTypeValue
25
- * @typedef {import("./entities/Outcome").OutcomeValue} OutcomeValue
26
- * @typedef {import("./entities/RollType").RollTypeValue} RollTypeValue
27
- * @typedef {import("./entities/TestType").TestTypeValue} TestTypeValue
28
- * @typedef {import("./entities/TestConditions").TestConditionsInstance} TestConditionsInstance
29
- */
30
- /**
31
- * @typedef {Object} RollTestOptions
32
- * @property {boolean} [useNaturalCrits] - If true, rolling the die's maximum value
33
- * triggers CriticalSuccess (for Skill tests) or Success (for AtLeast/AtMost tests),
34
- * and rolling 1 triggers CriticalFailure (for Skill tests) or Failure (for AtLeast)
35
- * or Success (for AtMost). If undefined, defaults to true for TestType.Skill
36
- * and false for all other test types.
37
- */
38
- /**
39
- * Rolls a die and evaluates it against specified test conditions.
40
- *
41
- * @function rollTest
42
- * @param {DieTypeValue} dieType - The type of die to roll (e.g., `DieType.D6`, `DieType.D20`).
43
- * @param {TestConditionsInstance|{ testType: TestTypeValue, [key: string]: any }} testConditions
44
- * Can be:
45
- * - A `TestConditions` instance.
46
- * - A plain object `{ testType, ...conditions }`.
47
- * @param {RollTypeValue} [rollType=undefined] - Optional roll mode (`RollType.Advantage` or `RollType.Disadvantage`).
48
- * @param {RollTestOptions} [options={}] - Optional configuration for natural crits
49
- * @returns {{ base: number, outcome: OutcomeValue }} The raw roll and its evaluated outcome.
50
- * @throws {TypeError} If `dieType` or `testConditions` are invalid.
51
- */
52
- declare function rollTest(dieType: DieTypeValue, testConditions: TestConditionsInstance | {
53
- testType: TestTypeValue;
54
- [key: string]: any;
55
- }, rollType?: RollTypeValue, options?: RollTestOptions): {
56
- base: number;
57
- outcome: OutcomeValue;
58
- };
59
- //# sourceMappingURL=rollTest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rollTest.d.ts","sourceRoot":"","sources":["../src/rollTest.js"],"names":[],"mappings":";;;;;;;oBA6Ba,OAAO,oBAAoB,EAAE,YAAY;oBACzC,OAAO,oBAAoB,EAAE,YAAY;qBACzC,OAAO,qBAAqB,EAAE,aAAa;qBAC3C,OAAO,qBAAqB,EAAE,aAAa;8BAC3C,OAAO,2BAA2B,EAAE,sBAAsB;;;;;;;;;;;AALvE;;;;;;GAMG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;;;;;GAaG;AACH,mCAVW,YAAY,kBACZ,sBAAsB,GAAC;IAAE,QAAQ,EAAE,aAAa,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,aAItE,aAAa,YACb,eAAe,GACb;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CA4BnD"}
@@ -1,45 +0,0 @@
1
- export type OutcomeValue = import("../entities/Outcome").OutcomeValue;
2
- export type TestConditionsInstance = import("../entities/TestConditions").TestConditionsInstance;
3
- export type Conditions = import("../entities/TestConditions").Conditions;
4
- export type TestTypeValue = import("../entities/TestType").TestTypeValue;
5
- export type DieTypeValue = import("../entities/DieType").DieTypeValue;
6
- export type TestConditionsLike = {
7
- testType: TestTypeValue;
8
- dieType: DieTypeValue;
9
- } & Conditions;
10
- /**
11
- * @typedef {import("../entities/Outcome").OutcomeValue} OutcomeValue
12
- * @typedef {import("../entities/TestConditions").TestConditionsInstance} TestConditionsInstance
13
- * @typedef {import("../entities/TestConditions").Conditions} Conditions
14
- * @typedef {import("../entities/TestType").TestTypeValue} TestTypeValue
15
- * @typedef {import("../entities/DieType").DieTypeValue} DieTypeValue
16
- */
17
- /**
18
- * @private
19
- * @typedef {{ testType: TestTypeValue, dieType: DieTypeValue } & Conditions} TestConditionsLike
20
- */
21
- /**
22
- * Determines the outcome of a roll based on provided {@link TestConditions}.
23
- * Returns standard {@link Outcome} values including success, failure, and criticals.
24
- *
25
- * @function determineOutcome
26
- * @param {number} value - The rolled (possibly modified) result.
27
- * @param {TestConditionsInstance|TestConditionsLike} testConditions - The conditions defining success/failure thresholds.
28
- * @returns {OutcomeValue} The resulting outcome.
29
- * @throws {TypeError} If the provided conditions or test type are invalid.
30
- *
31
- * @example
32
- * const test = new TestConditions(TestType.AtLeast, { target: 12 });
33
- * const outcome = determineOutcome(14, test);
34
- * console.log(outcome); // "success"
35
- *
36
- * @example
37
- * const skill = new TestConditions(TestType.Skill, {
38
- * target: 10,
39
- * critical_success: 20,
40
- * critical_failure: 1
41
- * });
42
- * console.log(determineOutcome(1, skill)); // "critical_failure"
43
- */
44
- export function determineOutcome(value: number, testConditions: TestConditionsInstance | TestConditionsLike): OutcomeValue;
45
- //# sourceMappingURL=determineOutcome.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"determineOutcome.d.ts","sourceRoot":"","sources":["../../src/utils/determineOutcome.js"],"names":[],"mappings":"2BAWa,OAAO,qBAAqB,EAAE,YAAY;qCAC1C,OAAO,4BAA4B,EAAE,sBAAsB;yBAC3D,OAAO,4BAA4B,EAAE,UAAU;4BAC/C,OAAO,sBAAsB,EAAE,aAAa;2BAC5C,OAAO,qBAAqB,EAAE,YAAY;iCAK1C;IAAE,QAAQ,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GAAG,UAAU;AAV5E;;;;;;GAMG;AAEH;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wCAlBW,MAAM,kBACN,sBAAsB,GAAC,kBAAkB,GACvC,YAAY,CAmDxB"}
@@ -1,30 +0,0 @@
1
- export type DieTypeValue = import("../entities/DieType").DieTypeValue;
2
- /**
3
- * Generates a single roll result for a given die type.
4
- *
5
- * @function generateResult
6
- * @param {DieTypeValue} dieType - The type of die to roll (e.g., "d6", "d20").
7
- * @returns {number} The result of rolling the die.
8
- * @throws {TypeError} If the die type is invalid.
9
- *
10
- * @example
11
- * const result = generateResult("d6");
12
- * console.log(result); // 1..6
13
- */
14
- export function generateResult(dieType: DieTypeValue): number;
15
- /**
16
- * @typedef {import("../entities/DieType").DieTypeValue} DieTypeValue
17
- */
18
- /**
19
- * Returns the number of sides on a die given its type.
20
- *
21
- * @function numSides
22
- * @param {DieTypeValue} dieType - The die type (e.g., "d6", "d20").
23
- * @returns {number} Number of sides.
24
- * @throws {TypeError} If the die type is invalid.
25
- *
26
- * @example
27
- * console.log(numSides("d6")); // 6
28
- */
29
- export function numSides(dieType: DieTypeValue): number;
30
- //# sourceMappingURL=generateResult.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateResult.d.ts","sourceRoot":"","sources":["../../src/utils/generateResult.js"],"names":[],"mappings":"2BASa,OAAO,qBAAqB,EAAE,YAAY;AAqBvD;;;;;;;;;;;GAWG;AACH,wCARW,YAAY,GACV,MAAM,CAUlB;AArCD;;GAEG;AAEH;;;;;;;;;;GAUG;AACH,kCAPW,YAAY,GACV,MAAM,CAWlB"}
@@ -1,8 +0,0 @@
1
- import { determineOutcome } from "./determineOutcome.js";
2
- import { generateResult } from "./generateResult.js";
3
- import { numSides } from "./generateResult.js";
4
- import { createOutcomeMap } from "./outcomeMapper.js";
5
- import { clearOutcomeMapCache } from "./outcomeMapper.js";
6
- import { getOutcomeMapCacheSize } from "./outcomeMapper.js";
7
- export { determineOutcome, generateResult, numSides, createOutcomeMap, clearOutcomeMapCache, getOutcomeMapCacheSize };
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.js"],"names":[],"mappings":""}