DiceRoller
DiceRoller
A DiceRoller handles dice rolling functionality, keeps a history of rolls and can output logs etc.
Kind: global class
See: DiceRoll if you don't need to keep a log history of rolls
- DiceRoller
- new DiceRoller([data])
 - instance
- .log ⇒ 
Array.<DiceRoll> - .output ⇒ 
string - .total ⇒ 
number - .clearLog()
 - .export([format]) ⇒ 
string|null - .import(data) ⇒ 
Array.<DiceRoll> - .roll(...notations) ⇒ 
DiceRoll|Array.<DiceRoll> - .toJSON() ⇒ 
Object - .toString() ⇒ 
string 
 - .log ⇒ 
 - static
 
 
new DiceRoller([data])
Create a DiceRoller.
The optional data property should be either an array of DiceRoll objects, or an object with a log property that contains the DiceRoll objects.
Throws:
TypeErrorif data is an object, it must have alog[]property
| Param | Type | Description | 
|---|---|---|
| [data] | Object | Array.<DiceRoll> | The data to import | 
| [data.log] | Array.<DiceRoll> | If data is an object, it must contain an array of DiceRolls | 
 diceRoller.log ⇒ Array.<DiceRoll>
The list of roll logs.
Kind: instance property of DiceRoller
 diceRoller.output ⇒ string
String representation of the rolls in the log
Kind: instance property of DiceRoller
Example
2d20+1d6: [20,2]+[2] = 24; 1d8: [6] = 6
 diceRoller.total ⇒ number
The sum of all the rolls in the log
Kind: instance property of DiceRoller
See: log
diceRoller.clearLog()
Clear the roll history log.
Kind: instance method of DiceRoller
See: log
 diceRoller.export([format]) ⇒ string | null
Export the object in the given format. If no format is specified, JSON is returned.
Kind: instance method of DiceRoller
Returns: string | null - The exported data, in the specified format
Throws:
TypeErrorInvalid export format
See: toJSON
| Param | Type | Default | Description | 
|---|---|---|---|
| [format] | exportFormats | exportFormats#JSON | The format to export the data as | 
 diceRoller.import(data) ⇒ Array.<DiceRoll>
Add the data to the existing roll log.
data can be an array of DiceRoll objects, an object with a log property that contains DiceRoll objects, or a JSON / base64 encoded representation of either.
Kind: instance method of DiceRoller
Returns: Array.<DiceRoll> - The roll log
Throws:
DataFormatErrordata format invalidRequiredArgumentErrordata is requiredTypeErrorlog must be an array
See: log
| Param | Type | Description | 
|---|---|---|
| data | string | Object | Array.<DiceRoll> | The data to import | 
| [data.log] | Array.<DiceRoll> | If data is an object, it must contain an array of DiceRolls | 
 diceRoller.roll(...notations) ⇒ DiceRoll | Array.<DiceRoll>
Roll the given dice notation(s) and return the corresponding DiceRoll objects.
You can roll a single notation, or multiple at once.
Kind: instance method of DiceRoller
Returns: DiceRoll | Array.<DiceRoll> - If a single notation is passed, a single DiceRoll is returned, otherwise an array of DiceRoll objects is returned
Throws:
NotationErrornotation is invalidRequiredArgumentErrornotation is required
| Param | Type | Description | 
|---|---|---|
| ...notations | string | The notations to roll | 
Example (Single notation)
diceRoller.roll('2d6');
Example (Multiple notations)
roll('2d6', '4d10', 'd8+4d6');
 diceRoller.toJSON() ⇒ Object
Return an object for JSON serialising.
This is called automatically when JSON encoding the object.
Kind: instance method of DiceRoller
 diceRoller.toString() ⇒ string
Return the String representation of the object.
This is called automatically when casting the object to a string.
Kind: instance method of DiceRoller
See: output
 DiceRoller.import(data) ⇒ DiceRoller
Create a new DiceRoller instance with the given data.
data can be an array of DiceRoll objects, an object with a log property that contains the DiceRoll objects, or a JSON / base64 encoded representation of either.
Kind: static method of DiceRoller
Returns: DiceRoller - The new DiceRoller instance
Throws:
DataFormatErrordata format invalidRequiredArgumentErrordata is requiredTypeErrorlog must be an array
See: instance method import
| Param | Type | Description | 
|---|---|---|
| data | string | Object | Array.<DiceRoll> | The data to import | 
| [data.log] | Array.<DiceRoll> | If data is an object, it must contain an array of DiceRolls |