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

rolldice

v3.0.0

Published

A library to roll some dice.

Downloads

133

Readme

Roll some dice

Build Status

Installation

The RollDice library should run under pretty much any version of node. Note: this package is from the "library" branch of the repository, and has been isolated from any specific bot's plugin libraries.

  1. npm install rolldice --save
  2. Require and use the dice in your application
const DiceRoll = require('rolldice');

// create and evaluate a dice rolling expression
let dice = new DiceRoll('d4 + 2d12 + 3d3 for great justice');

// get the boolean value of the expression's validity check
let syntaxIsValid = dice.expression.isValid;
// > true

// get the numerical value of the expression
let rollTotal = dice.expression.result;
// > 27

// get a string description of each roll result within the specified expression
let rollDetails = dice.expression.toDetails();
// > 'Total: 27\r\nFormula: 1d4 + 2d12 + 3d3\r\nRolls:\r\n(1d4) [4] = 4\r\n(2d12) [6,11] = 17\r\n(3d3) [1,3,2] = 6'

// get a string representation of the roll total and roll details
console.log('For', dice.toString());
// > For great justice: 18 rolls: 1d4(2=2) + 2d12(11=8+3) + 3d3(5=2+1+2)

// display a readout of all the syntax supported by the dice rolling parser
console.log(new DiceRoll('help').toString());

Supported syntax

Supports standard dice notation, as well as some extended functionality.
syntax: <roll>[<operator><roll><operator><roll>...][<operator><constant>]
roll: [<number of dice>]d<number of sides>[<modifiers>]
      default number of dice: 1
number of sides: any integer, or f (for Fudge dice)
operator: +, -, *, /, %, (, or )
constant: any integer
modifiers:
  ! - exploding dice, a maximum roll value causes recursive reroll and summation
  d<number> - drop the lowest X rolls from this group
  k<number> - keep the highest X rolls from this group
  h - alter either d or k modifier to affect the highest rolls, e.g. dh3: drop the highest 3 rolls
  l - alter either d or k modifier to affect the lowest rolls, e.g. kl2: keep the lowest 2 rolls
  r - reroll based on certain rules
    r4 - reroll all 4s
    r<3 - reroll anything less than 3
    r>=11 - reroll anything greater than or equal to 11
modifiers can be combined, but d and k are mutually exclusive

Issues/contributing

I'm open to contributions with pull requests. This is not a primary project for me in any way, so don't expect a lot of expedience on issues.

Hubot

If you want my rolldice library for hubot, check npm for hubot-rolldice, or see the mentalspike/hubot-rolldice.

License

This script has been released under the MIT license.