@damienbullis/dice
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

Dice


Top Language Downloads Version

codecov Build


🎲 Comes with all the basic polyhedral dice 🎲

🎲 Simple interface for creating custom or 'funky' dice 🎲

🎲 Pools is a simple helper for rolling multiple dice 🎲




Install

npm install @damienbullis/dice
# or
yarn add @damienbullis/dice
# or
pnpm add @damienbullis/dice

Usage

Basic Usage

To roll dice, you can use the Dice function.


import { Dice } from "@damienbullis/dice";

// Create some dice
const d4 = Dice(4);
const d6 = Dice(6);
const d8 = Dice(8);

d4(); // rolls a single d4
// returns [ 2 ]

d6(2); // rolls two d6's
// returns [ 3, 6 ]

d8(3); // rolls three d8's
// returns [ 8, 2, 2 ]

Using Custom Dice

If you have a need for dice with symbols, multiple values per facing, or to change the probability curve.


import { Dice } from "@damienbullis/dice";

// Create a custom die
const SuccessDie = Dice([
  "Success+Crit",
  "Success",
  "Success",
  "Failure+Crit",
  "Failure",
  "Failure",
]);

SuccessDie(); // rolls the die once
// returns [ "Failure+Crit" ]

Using a Pool

To roll a pool of dice, you can use the Pool function in conjunction with the Dice function.


import { Dice, Pool } from "@damienbullis/dice";

const d6 = Dice(6);
const d20 = Dice(20);

// Create a pool of dice
const pool = Pool(d6, d20);

pool(); // rolls the pool once
// returns [ [ 3, 20 ] ]
pool(2); // rolls the pool twice
// returns [ [ 6, 12 ], [ 1, 18 ] ]



Roadmap

  • [x] Add error handling
  • [x] Add tests
  • [x] Publish to NPM
  • [ ] Better Types*
  • [ ] Custom Weights for Dice*
  • [ ] Custom Random Number Generator's*

*Not sure about these yet...


Contributing

Contributions are welcome! Please open an issue or PR.


License

MIT © damienbullis

Package Sidebar

Install

npm i @damienbullis/dice

Weekly Downloads

0

Version

0.2.3

License

MIT

Unpacked Size

9.27 kB

Total Files

6

Last publish

Collaborators

  • damienbullis