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

    Function roll

    • Parses and evaluates a dice notation string in one call — the main entry point of the library.

      Equivalent to evaluate(parse(notation), rng, { notation }). Each call builds a fresh SeededRNG unless options.rng is supplied, so reuse parse + evaluate directly when rolling the same notation in a loop.

      Parameters

      Returns RollResult

      Complete RollResult with total, per-die results and the structured parts tree

      On an invalid character

      On invalid syntax

      On a limit breach or an impossible expression

      INVALID_EVALUATION_LIMIT when a supplied limit is not an integer in range — raised before any die is rolled

      INVALID_NOTATION_TYPE when notation is not a string, so isRollParserError still filters untrusted input completely

      import { roll } from 'roll-parser';

      // Random roll
      roll('2d6+3').total; // 5..15

      // Seeded — same seed, same sequence
      roll('2d6+3', { seed: 'demo' }).rendered; // '2d6[1, 6] + 3 = 10'
      roll('2d6+3', { seed: 'demo' }).total; // 10
      import { roll } from 'roll-parser';
      import { createMockRng } from 'roll-parser/testing';

      const result = roll('4d6kh3', { rng: createMockRng([3, 6, 2, 5]) });
      result.total; // 14
      result.rendered; // '4d6[3, 6, ~~2~~, 5] = 14'