Skip to content

mog13/DXJS

Repository files navigation

DXJS

codecov

DXJS is a library for simulating dice rolls commonly used in tabletop games. It provides a range of standard dice from d2 to d100, as well as the ability to define and roll custom dice. The library allows dice rolls to be specified both programmatically and via an interpreted string format, making it highly versatile for various use-cases.

Installation

npm install @mog13/dxjs

Usage

const { Dice, roll } = require('@mog13/dxjs');

// roll standard dx dice
roll("d20"); // 1-20
roll("2d20 + 1d6"); // 3-46
roll("d1+d2+d3+d4+d5+d6+d7+d8+d9"); // 9-45

// create your own dice
const myNewDice = new Dice("myNewDice", [0,25,50,75,100]);
myNewDice.roll(); // 0-100
roll("myNewDice"); // 0-100
roll("5myNewDice * d4"); // 0-2000