RollTerm

RollTerm

An abstract class which represents a single token that can be used as part of a Roll formula. Every portion of a Roll formula is parsed into a subclass of RollTerm in order for the Roll to be fully evaluated.

Constructor

new RollTerm()

Members

_evaluated :boolean

An internal flag for whether the term has been evaluated

Type:
  • boolean

expression :string

A string representation of the formula expression for this RollTerm, prior to evaluation.

Type:
  • string

flavor :string

Optional flavor text which modifies and describes this term.

Type:
  • string

FLAVOR_REGEXP :RegExp

A regular expression which identifies term-level flavor text

Type:

FLAVOR_REGEXP_STRING :string

A regular expression pattern which identifies optional term-level flavor text

Type:
  • string

formula :string

A string representation of the formula, including optional flavor text.

Type:
  • string

isIntermediate :boolean

Is this term intermediate, and should be evaluated first as part of the simplification process?

Type:
  • boolean

options :object

An object of additional options which describes and modifies the term.

Type:
  • object

REGEXP :RegExp

A regular expression used to match a term of this type

Type:

SERIALIZE_ATTRIBUTES :Array.<string>

An array of additional attributes which should be retained when the term is serialized

Type:

total :number|string

A string or numeric representation of the final output for this term, after evaluation.

Type:
  • number | string

Methods

(protected, static) _fromData(data) → {RollTerm}

Define term-specific logic for how a de-serialized data object is restored as a functional RollTerm

Parameters:
Name Type Description
data object

The de-serialized term data

Returns:

The re-constructed RollTerm object

Type
RollTerm

(static) fromData(data) → {RollTerm}

Construct a RollTerm from a provided data object

Parameters:
Name Type Description
data object

Provided data from an un-serialized term

Returns:

The constructed RollTerm

Type
RollTerm

(static) fromJSON(json) → {RollTerm}

Reconstruct a RollTerm instance from a provided JSON string

Parameters:
Name Type Description
json string

A serialized JSON representation of a DiceTerm

Returns:

A reconstructed RollTerm from the provided JSON

Type
RollTerm

evaluate(optionsopt) → {RollTerm}

Evaluate the term, processing its inputs and finalizing its total.

Parameters:
Name Type Attributes Default Description
options object <optional>
{}

Options which modify how the RollTerm is evaluated

Properties
Name Type Attributes Default Description
minimize boolean <optional>
false

Minimize the result, obtaining the smallest possible value.

maximize boolean <optional>
false

Maximize the result, obtaining the largest possible value.

async boolean <optional>
false

Evaluate the term asynchronously, receiving a Promise as the returned value. This will become the default behavior in version 10.x

Returns:

The evaluated RollTerm

Type
RollTerm

toJSON() → {object}

Serialize the RollTerm to a JSON string which allows it to be saved in the database or embedded in text. This method should return an object suitable for passing to the JSON.stringify function.

Returns:
Type
object