A simple library for simulating dice rolls for use in RPG games :)
Using npm
npm install nat20
import { DiceRoller, d } from "nat20";
const diceRoller = new DiceRoller();
diceRoller.roll("2d6"); // Should return a number between 2 and 12
diceRoller.roll("2a6"); // Should throw an erro due to this being an invalid expression
// Alternatively, you can use a callback
diceRoller.roll("d6 + 6", (result, error) => {
// The result should be a number between 7 anad 12
// If there has been an error, you can access it here instead of it being thrown
});
// You can also simply roll a single dice, taking the number of sides as a parameter
const result = d(20) // Should return a number between 1 and 20