JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q48106F
  • License ISC

Rolls dice according to RPG dice notation (e.g. 1d4, d6, 2d6+5, 1d20-1)

Package Exports

  • dnd5e-dice-roller
  • dnd5e-dice-roller/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dnd5e-dice-roller) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dnd5e-dice-roller

npm Version Build NPM License size

Generate dice rolls based on standard ttrpg dice string.

For example:s

  • 1d4 - 1 roll of a 4 sided dice. Returns a result between 1 and 4
  • d6 - 1 roll of a 6 sided dice. Returns a result between 1 and 6
  • 3d8 - 3 rolls of an 8 sided dice. Returns a result between 3 and 24
  • 1d6+2 - 1 roll of a 6 sided dice, plus 2. Returns a result between 3 and 8
  • 1d4-1 - 1 roll of a 4 sided dice, minus 1. Returns a result between 0 and 3
  • 4d6dl1 - 4 rolls of a 6 sided dice, dropping the lowest. Returns a result between 3 and 18
  • 2d20dh1 - 2 rolls of a 20 sided dice, dropping the lowest. (i.e. Rolling with disadvantage)
  • 2d20d1+3 - 2 rolls of a 20 sided dice, dropping the lowest, plus 3. (i.e. Rolling with advantage with a modifier)

Usage

Default export returns the total and the the rolls of each die

import diceRoller  from 'dnd5e-dice-roller';

diceRoller("2d8+3"); // Returns { total: 17, rolls: [8, 6], rollStr: "2d8+3"  }

Named exports of diceRoller (behaves the same as the default) and roll to just return the total

import { diceRoller, roll }  from 'dnd5e-dice-roller';

diceRoller("2d8+3"); // Returns { total: 17, rolls: [8, 6], rollStr: "2d8+3"  }
roll("2d8+3"); // Returns 17