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

diceroll

v2.0.1

Published

A dice roller for gaming

Downloads

20

Readme

DiceRoll

A simple dice rolling lib for Node or the browser, written in Coffee, distributed as compiled JS.

Usage

Clone this repo or install hrough npm:

npm install diceroll

Include the library client side:

<script src="node_modules/diceroll/diceroll.min.js"></script>

Or server side in Node:

var diceroll = require("diceroll");

Require the function and do a roll:

var roll = diceroll({ dice: 2, sides: 20 });
console.log(roll);

The roll results in a json object with the following:

{
  rolls: [ 17, 5 ],
  conclusion: 22
}

'rolls' contains the result of each die roll, conclusion contains the total result. By default the conclusion is the sum of the rolls, but this can be configured.

The following parameters are currently supported:

  • dice [number] (mandatory): the amount of dice to roll
  • sides [number] (mandatory): how many sides each die should have
  • sum [bool]: Whether the conclusion should summarize the rolls or not
  • target [number]: If sum is false, the conclusion will instead contain the amount of rolls that reach or exceed this target number. If, however, sum is true and target number is set, the conclusion will contain a boolean true or false depending on whether or not the target number was met.
  • onesSubtract [bool]: If sum is false, any 1s rolled will subtract from the conclusion, possibly making it negative.
  • explodeOn [number]: If sum is false, an extra die will be rolled anytime a die hits or exceeds this number.
  • modifier [number]: Negative or positive number to subtract from or add to the sum conclusion. Has no effect on sum:false rolls.

Example using a target number (6, as is the case in the Vampire: the Masquerade RPG for instance):

var roll = diceroll({ dice: 5, sides: 10, sum: false, target: 6, onesSubtract: true });
console.log(roll);

The result yielded could look like this:

{
  rolls: [3, 10, 4, 2, 8],
  conclusion: 2
}

Example using a target number on a summarized roll (such as a D&D d20 roll):

var roll = diceroll({ dice: 1, sides: 20, target: 12 });
console.log(roll);

The result yielded could look like this:

{
  rolls: [ 9 ],
  conclusion: false
}

You can roll multiple dice types in the same diceroll. This creates nested diceroll instances that sum their conclusions together and returns their rolls in an array of arrays. Note that if you use a target number with sum:true, the boolean conclusion will be skipped. With sum:false the number of successful target hits gets added to the conclusion (rather than the sum of the rolls).

Example using multiple dice in the same roll:

var roll = diceroll([ { dice: 1, sides: 6 }, { dice: 2, sides: 4, modifier: 1 } ]);
console.log(roll);

The result yielded could look like this:

{
  rolls: [ [ 3 ], [ 1, 4 ] ],
  conclusion: 9 // sum of the rolls is 8, modifier to the last roll is 1, for a total of 9
}

If you wish to run the unit tests for diceroll, enter the module directory and run:

npm test

Contribution

The licence for this software is found in LICENCE.txt. Pull requests and issues are always welcome.