@2toad/d20
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

d20

GitHub version Downloads Build status

A magic bag of JavaScript dice (with TypeScript support)

Getting Started

Install package

npm i @2toad/d20

Usage

import { d20 } from '@2toad/d20';
// or
var d20 = require('@2toad/d20');

d20.roll('1d20');

API

Methods

roll(notation: string): number

  • Rolls NdX specified dice
  • Where N is the number of dice, and X is the number of sides each die has
  • Returns the sum of the resulting rolls
// roll one 20-sided die
d20.roll('1d20');
// Possible results: 1-20

// roll four 6-sided dice
d20.roll('4d6');
// Possible results: 4-24

dice(notation: string): number[]

Same as roll(), except the result of each die roll is returned in an array

// roll one 20-sided die
d20.dice('1d20');
// Possible results: [1-20]

// roll four 6-sided dice
d20.dice('4d6');
// Possible results: [1-6, 1-6, 1-6, 1-6]

Package Sidebar

Install

npm i @2toad/d20

Weekly Downloads

2

Version

1.2.0

License

MIT

Unpacked Size

11.5 kB

Total Files

13

Last publish

Collaborators

  • jasonpierce