JSPM

@damienbullis/dice

0.2.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q35735F
  • License MIT

A dice rolling package for rolling polyhedral & funky dice

Package Exports

  • @damienbullis/dice
  • @damienbullis/dice/dist/index.js
  • @damienbullis/dice/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@damienbullis/dice) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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

  • 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