trpg-dice
Tabletop RPG dice-roller with a multiple dice-types, rolling methods, minimum and maximum values, string output, and error-first callbacks.
Installation
npm install trpg-dice
Usage
To use the library, import the module and call the roll()
method with a dice expression, an optional options
parameter, and a callback function. Dice expressions with standard <number of dice>d<number of sides>
are all supported as well as simple math. To roll Fate/Fudge dice, use dF
or df
for the dice expression.
const dice = ; { if err throw err; else console; } dice;dice; // will roll d20-2 for 10 timesdice; // will roll Fate/Fudge dicedice;dice;
The roll()
method is an error-first callback that invokes the callback function with an error (or null if none) and an object with the original dice expression, minimum, maximum, average, and roll results.
expression: '2d6+2' min: 4 max: 14 avg: 9 rolls: result: 12 resultString: '(5+5)+2' condensedResultString: '(10)+2' result: 8 resultString: '(1+5)+2' condensedResultString: '(6)+2' result: 11 resultString: '(3+6)+2' condensedResultString: '(9)+2' result: 5 resultString: '(2+1)+2' condensedResultString: '(3)+2' result: 8 resultString: '(5+1)+2' condensedResultString: '(6)+2' result: 13 resultString: '(6+5)+2' condensedResultString: '(11)+2' result: 9 resultString: '(5+2)+2' condensedResultString: '(7)+2' result: 9 resultString: '(4+3)+2' condensedResultString: '(7)+2' result: 8 resultString: '(4+2)+2' condensedResultString: '(6)+2' result: 8 resultString: '(4+2)+2' condensedResultString: '(6)+2'
Options
The following options are currently supported:
- roll - specifies the amount of times the dice expression should be rolled, increasing the number of roll results returned in the object