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

d20

v1.4.1

Published

Library for rolling dice based on dice-syntax used in RPGs.

Downloads

162

Readme

d20.js

Javascript library for rolling RPG dice. Supports dice notation such as "4d6" and "d20+2".

npm version Build Status

Installation

In the browser

Download the files from GitHub and include the d20.js file somewhere in your HTML page.

<script src="path/to/d20.js"></script>

As a Node.js module

Install via npm.

npm install d20

require it in your app.

var d20 = require('d20');

As a standalone tool

Install it globally.

npm install -g d20

Run the d20 command with any number of desired dice rolls after.

d20 4d6
d20 d20 1d8+1 d4

Usage

As a library

Both methods of using the library provides a d20 object with the roll() method which is used to roll dice.

d20.roll(20); // roll a 20-sided die
d20.roll('4d6'); // roll four 6-sided dice
d20.roll('2d8+1'); // roll two 8-sided dice and add 1 to the result
d20.roll('1d8 +1 +2 -20'); // roll an 8-sided die with multiple modifiers

You can get the result as an array of values rather than a single result if you use the verboseRoll function. Note that the results will be sorted in ascending order except for the modifiers which will be in their order of apperance.

d20.verboseRoll(20);
d20.verboseRoll('4d6');
d20.verboseRoll('2d8+1');
d20.verboseRoll('1d8 +1 +2 -20');

Alternatively you can just pass true as the second paramenter to the roll function.

d20.roll(20, true);
d20.roll('4d6', true);
d20.roll('2d8+1', true);
d20.roll('1d8 +1 +2 -20', true);

As a standalone tool

The standalone tool takes any number of dice roll commands and will return each one separately.

d20 4d6 2d8 d10

If you want more verbose output (full list of results per dice), you can use the --verbose option.

d20 --verbose 3d12

If you add the --total option, it will return the sum of all the dice rolls.

d20 --total d20 1d8+1 d4

Testing

The library can be tested by installing the dependencies and running npm test:

npm install
npm test