d-parser

1.0.3 • Public • Published

dice-roller

This module is designed to do generic dice rolling. It exposes three functions but the most important one is the roll function.

Basic Usage

To get access to the dice-roller function:

//es2015 imports
import { roll } from 'dice-roller';
 
//commonjs
let { roll } = require('dice-roller');
 
//script
let roll = dr.roll;

Simple Rolls

Simple rolls look like this.

roll('1d20');
//{ text: '18', value: 18 }
 

Addition and Subtraction

Any addition or subtraction will show you the grouped results of each set of dice.

roll('3d10 + 6d20');
//{ text: '10 + 60', value: 70 }
 
roll('5d6 + 3d10 - 3d4');
//{ text: '10 + 13 - 8', value: 15 }
 
//static numbers work too
roll('1d20 + 2');
//{ text: '15 + 2', value: 17 }

Multiplication and Grouping

The "*" symbol must explicitly be used, but it logically groups the "Order of Operations" correctly.

roll('3d10 * 3d10');
//{ text: '24 * 10', value: 240 }
 
roll('4 + 5 * 2d10')
//{ text: '4 + 5 * 4', value: 24 }

Grouping works too.

roll('(5d6 + 3d10 - 3d4) * 2');
//{ text: '(16 + 12 - 9) * 2', value: 38 }

Dependents (0)

Package Sidebar

Install

npm i d-parser

Weekly Downloads

1

Version

1.0.3

License

MIT

Last publish

Collaborators

  • jtenner