ParentheticalTerm

ParentheticalTerm

A type of RollTerm used to enclose a parenthetical expression to be recursively evaluated.

Constructor

new ParentheticalTerm()

Extends

Members

_evaluated :boolean

Overrides:

An internal flag for whether the term has been evaluated

Type:
  • boolean

CLOSE_REGEXP :RegExp

A regular expression pattern used to identify the closing of a parenthetical expression.

Type:

dice :Array.<DiceTerm>

An array of evaluated DiceTerm instances that should be bubbled up to the parent Roll

Type:

expression :string

Overrides:

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

Type:
  • string

flavor :string

Overrides:

Optional flavor text which modifies and describes this term.

Type:
  • string

FLAVOR_REGEXP :RegExp

Overrides:

A regular expression which identifies term-level flavor text

Type:

FLAVOR_REGEXP_STRING :string

Overrides:

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

Type:
  • string

formula :string

Overrides:

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

Type:
  • string

isIntermediate :boolean

Overrides:

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

Type:
  • boolean

OPEN_REGEXP :RegExp

The regular expression pattern used to identify the opening of a parenthetical expression. This could also identify the opening of a math function.

Type:

options :object

Overrides:

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

Type:
  • object

REGEXP :RegExp

Overrides:

A regular expression used to match a term of this type

Type:

roll :Roll

Alternatively, an already-evaluated Roll instance may be passed directly

Type:

SERIALIZE_ATTRIBUTES :Array.<string>

Overrides:

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

Type:

term :string

The original provided string term used to construct the parenthetical

Type:
  • string

total :number|string

Overrides:

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

Type:
  • number | string

Methods

(static) fromTerms(terms, optionsopt) → {ParentheticalTerm}

Construct a ParentheticalTerm from an Array of component terms which should be wrapped inside the parentheses.

Example

Create a Parenthetical Term from an array of component RollTerm instances

const d6 = new Die({number: 4, faces: 6});
const plus = new OperatorTerm({operator: "+"});
const bonus = new NumericTerm({number: 4});
t = ParentheticalTerm.fromTerms([d6, plus, bonus]);
t.formula; // (4d6 + 4)
Parameters:
Name Type Attributes Default Description
terms Array.<RollTerm>

The array of terms to use as internal parts of the parenthetical

options object <optional>
{}

Additional options passed to the ParentheticalTerm constructor

Returns:

The constructed ParentheticalTerm instance

Type
ParentheticalTerm

evaluate(optionsopt) → {RollTerm}

Overrides:

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}

Overrides:

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