roll-parser - v3.4.0
    Preparing search index...

    Type Alias EvaluationOptions

    Evaluation guardrails and variable resolution, shared by EvaluateOptions and RollOptions. Every field is optional — the defaults bound adversarial notation without capping any realistic expression.

    Tighten them when the notation comes from users you do not control; the caps are the difference between a typed EvaluatorError and a request that rolls ten million dice. Parse depth is capped separately and unconditionally by MAX_PARSE_DEPTH.

    The three numeric limits fail closed: omit one — or pass undefined or null, the no-options path a partial config produces — and it takes its default, but supply anything else that is not a safe integer in range — a string, NaN, ±Infinity, a negative, a fraction — and evaluation throws INVALID_EVALUATION_LIMIT before rolling. maxDice accepts >= 1, the two iteration limits >= 0. No coercion: maxDice: Number(input) on unparseable input rejects rather than quietly reverting to the permissive default.

    import { isRollParserError, roll } from 'roll-parser';

    const limits = {
    maxDice: 100,
    maxExplodeIterations: 20,
    maxRerollIterations: 20,
    };

    try {
    roll('99999d6', limits).total;
    } catch (error) {
    isRollParserError(error) && error.code; // 'DICE_LIMIT_EXCEEDED'
    }
    import { roll } from 'roll-parser';

    roll('1d20+@str', { context: { str: 4 }, seed: 'demo' }).total; // 5
    roll('1d20+@str', { onMissingVariable: 'zero', seed: 'demo' }).total; // 1
    type EvaluationOptions = {
        context?: Readonly<Record<string, number>>;
        maxDice?: number;
        maxExplodeIterations?: number;
        maxRerollIterations?: number;
        onMissingVariable?: "throw" | "zero";
    }
    Index
    context?: Readonly<Record<string, number>>

    Variable context for @name / @{name} references (default: empty)

    maxDice?: number

    Maximum total dice allowed per evaluation; integer >= 1 (default: 10,000)

    maxExplodeIterations?: number

    Maximum explosion iterations allowed per die; integer >= 0 (default: 1,000)

    maxRerollIterations?: number

    Maximum reroll iterations allowed per die; integer >= 0 (default: 1,000)

    onMissingVariable?: "throw" | "zero"

    Behavior when a referenced variable is missing from context (default: 'throw')