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 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-d20

v1.0.3

Published

Your friendly neighbourhood dice roller - for any RPG! Based on standard dice syntax. Supports standard rolls, keep highest/lowest, and modifiers.

Downloads

260

Readme

Dice Roller for RPG Games

Introduction

This Dice Roller provides a comprehensive set of tools to simulate dice rolls as part of tabletop RPG games like Dungeons & Dragons. It includes functionality to roll any number of dice with any number of sides, apply modifiers, and optionally keep the highest or lowest rolls. It is based on, and uses the same syntax as the Avrae D20 module for Python.

Features

  • Roll any number of dice with any specified number of sides.
  • Apply arithmetic modifiers to the sum of dice rolls.
  • Keep only the highest or lowest results from the rolls.
  • Detailed and customizable logging for debugging or game tracking.

Installation

This module is easy to install via npm:

npm install js-d20

Usage

To use this library, first import the functions you need from the package:

const { roll } = require('js-d20');

Then, you can use the roll function to execute dice rolls:

let result = roll("2d10+5");
console.log(result.toString()); // Outputs: 2d20 (4, 8) +5 = `17`
console.log(result.total()); // Outputs: 17

Or

roll("d20-2"); // Outputs: Result: d20 (16) -2 = `14`

Example Dice Roll Strings

  • Single Die Roll: 1d20 - Rolls one 20-sided die.
  • Multiple Dice Roll: 4d6 - Rolls four 6-sided dice.
  • Add Modifier: 2d10+5 - Rolls two 10-sided dice and adds 5 to the total.
  • Subtract Modifier: 2d8-3 - Rolls two 8-sided dice and subtracts 3 from the total.
  • Keep Highest: 4d6kh3 - Rolls four 6-sided dice and keeps the highest three rolls.
  • Keep Lowest: 5d20kl3 - Rolls five 20-sided dice and keeps the lowest three rolls.
  • Combined Modifiers: 3d6kh2+4 - Rolls three 6-sided dice, keeps the highest two rolls, and adds 4 to the total.

License:

This project is licensed under MIT License.