npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dnd-dice-roll

v1.2.0

Published

A dnd dice rolling package

Readme

D&D Dice Roll NPM Package

A lightweight and versatile dice-rolling package for D&D and other tabletop RPGs. This package supports rolling various types of dice, applying modifiers, and even simulating advantage (inspiration) and disadvantage (disspiration).


Version 1.2.0

  • Replaced inspiration() and disspiration() with advantage() and disadvantage() methods.
  • added abilityScore() method.
  • added hundredSides() method.

Installation

Install the package via npm:

npm install dnd-dice-roll

Usage

Import the package in your project:

import rollDice from 'dnd-dice-roll';

Basic Rolls

Roll a single d20:

console.log(rollDice.twentySides());
// Example output: 15

Roll 3d6 with a +2 modifier:

console.log(rollDice.numberOfRolls(3).sixSides(2));
// Example output: 14

Helper Methods

roll()

Explicitly returns the total roll value.

const roll = rollDice(1, 20);
console.log(roll.roll());
// Example output: 12

advantage()

Simulates rolling with advantage by rolling an additional die and taking the higher result.

console.log(rollDice.twentySides().advantage());
// Example output: 18 (higher of the two rolls)

disadvantage()

Simulates rolling with disadvantage by rolling an additional die and taking the lower result.

console.log(rollDice.twentySides().disadvantage());
// Example output: 10 (lower of the two rolls)

average()

Returns the average of the rolls, including any modifiers.

console.log(rollDice.numberOfRolls(5).sixSides().average());
// Example output: 3.80

noZero()

Ensures the total roll value is at least 1.

console.log(rollDice.twentySides(-20).noZero());
// Example output: 1

minValue(min)

Ensures the total roll value is at least the specified minimum.

console.log(rollDice.tenSides(-5).minValue(10));
// Example output: 10

abilityScore()

Returns an object with the results of rolling 4d6, discarding the lowest roll, and summing the remaining three.

console.log(rollDice.abilityScore());
// Example output: { roll1: 4, roll2: 6, roll3: 3, roll4: 2, total: 15 }

Predefined Dice Rollers

The package includes shortcuts for common dice types:

  • fourSides(numRolls = 1, modifier = 0)
  • sixSides(numRolls = 1, modifier = 0)
  • tenSides(numRolls = 1, modifier = 0)
  • twentySides(numRolls = 1, modifier = 0)
  • hundredSides(numRolls = 1, modifier = 0)

Example:

console.log(rollDice.fourSides());
// Example output: 3
console.log(rollDice.hundredSides(2, 5));
// Example output: 112

Chaining Methods

Methods like .noZero(), .inspiration(), and .disspiration() can be chained for complex rolls.

console.log(rollDice.numberOfRolls(3).sixSides(-2).noZero().inspiration());
// Example output: 12

Error Handling

The package ensures valid inputs:

  • Number of Rolls: Must be a positive integer.
  • Number of Sides: Must be a positive integer.
  • Modifier: Must be an integer.

Invalid inputs throw an error.

Example:

try {
    console.log(rollDice(-1, 6));
} catch (error) {
    console.error(error.message);
    // Output: Number of rolls must be a positive integer.
}

License

This project is licensed under the MIT License.


Keywords

dice roll, D&D dice, tabletop RPG, dice roller, d20, dice rolling, Dungeons and Dragons, RPG utilities, advantage rolling, npm dice package