0.2.3 • Published 2 years ago

@damienbullis/dice v0.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Top Language Downloads Version

codecov Build

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

  • Add error handling
  • Add tests
  • 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

0.2.1

2 years ago

0.2.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.1.0

2 years ago