Git Product home page Git Product logo

d20.js's Introduction

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

d20.js's People

Contributors

amirbaksh02 avatar ankr avatar eritbh avatar javiercejudo avatar mfazio23 avatar michaelenger avatar silveryard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

d20.js's Issues

NaN when doing straight math

I've run into an issue using the d20 package where, if I give it just math like "20 + 4", then it returns NaN. Seems very odd that it should fail to perform a basic mathematical calculation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.