The AST to evaluate, from parse or hand-built
Randomness source; one nextInt call per die
Evaluation limits plus the original notation string,
which the AST cannot supply
Complete RollResult
INVALID_EVALUATION_LIMIT when a supplied limit is
not an integer in range — raised before any die is rolled
import { evaluate, parse } from 'roll-parser';
import { createMockRng } from 'roll-parser/testing';
const ast = parse('2d6+3');
const result = evaluate(ast, createMockRng([4, 2]), { notation: '2d6+3' });
result.total; // 9
result.rendered; // '2d6[4, 2] + 3 = 9'
Omitting notation falls back to the normalized expression, which is
reconstructed from the AST — so RollResult.notation is always a string,
just not necessarily the one the user typed.
Evaluates a parsed AST against an RNG and returns the roll result.
The second half of the pipeline — roll is
evaluate(parse(...)). Call it directly to reuse one AST across many rolls, or to drive a hand-built AST.Unlike
roll, the RNG is required:evaluatenever invents a randomness source, so a caller can never accidentally get an unseeded roll.