• Public
  • Public/Protected
  • All

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.




  • new RollTerm(__namedParameters?: { options: {} }): RollTerm
  • Parameters

    • __namedParameters: { options: {} } = {}
      • options: {}

      Returns RollTerm


    options: any

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

    _evaluated: boolean

    An internal flag for whether the term has been evaluated

    isIntermediate: boolean = false

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

    FLAVOR_REGEXP_STRING: string = "(?:\\[([^\\]]+)\\])"

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

    FLAVOR_REGEXP: RegExp = ...

    A regular expression which identifies term-level flavor text

    REGEXP: RegExp = undefined

    A regular expression used to match a term of this type

    SERIALIZE_ATTRIBUTES: string[] = []

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


    • get expression(): string
    • A string representation of the formula expression for this RollTerm, prior to evaluation.

      Returns string

    • get formula(): string
    • A string representation of the formula, including optional flavor text.

      Returns string

    • get total(): string | number
    • A string or numeric representation of the final output for this term, after evaluation.

      Returns string | number

    • get flavor(): string
    • Optional flavor text which modifies and describes this term.

      Returns string

    • get isDeterministic(): boolean
    • Whether this term is entirely deterministic or contains some randomness.

      Returns boolean


    • evaluate([options={}]?: { minimize: boolean; maximize: boolean; async: boolean }): RollTerm
    • Evaluate the term, processing its inputs and finalizing its total.


      • [options={}]: { minimize: boolean; maximize: boolean; async: boolean } = {}

        Options which modify how the RollTerm is evaluated

        • minimize: boolean
        • maximize: boolean
        • async: boolean

      Returns RollTerm

      The evaluated RollTerm

    • toJSON(): any
    • 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 any

    • _evaluate([options={}]?: any): Promise<RollTerm>
    • Evaluate the term.


      • [options={}]: any = {}

        Options which modify how the RollTerm is evaluated, see RollTerm#evaluate

      Returns Promise<RollTerm>

    • _evaluateSync(__namedParameters?: { minimize: boolean; maximize: boolean }): RollTerm
    • This method is temporarily factored out in order to provide different behaviors synchronous evaluation. This will be removed in 0.10.x


      • __namedParameters: { minimize: boolean; maximize: boolean } = {}
        • minimize: boolean
        • maximize: boolean

      Returns RollTerm

    • Construct a RollTerm from a provided data object


      • data: any

        Provided data from an un-serialized term

      Returns RollTerm

      The constructed RollTerm

    • Reconstruct a RollTerm instance from a provided JSON string


      • json: string

        A serialized JSON representation of a DiceTerm

      Returns RollTerm

      A reconstructed RollTerm from the provided JSON

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


      • data: any

        The de-serialized term data

      Returns RollTerm

      The re-constructed RollTerm object