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

0.2.2 • Public • Published

roll-dice

Evaluate standard dice roll notation.

$ npm i roll-dice@npm:jprochazk/roll-dice
import { roll } from "roll-dice";

roll("5d6") // roll a 6-sided die 5 times.
roll("5d6 + 10") // roll a 6-sided die 5 times, and add 10 to the result.

Syntax

description example
a + b add a and b 1 + 1
a - b subtract b from a 1 - 1
a * b multiply a by b 1 * 1
a / b divide a by b 1 / 1
- b negates b -1
d a rolls an a-sided die d5
a d b rolls a b-sided die, a times 2d10
( a ) grouping expression, used to specify precedence (1+1)

Every a or b in the above table may contain another expression, and expressions may be arbitrarily nested. For example (10+5)*2+(5d10) is a valid expression.

Structure

The library is written in Rust, and uses wasm-pack for packing it as a WASM module and publishing it on NPM. Various commands (available in the justfile) are run using just.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependents (0)

Package Sidebar

Install

npm i @jprochazk/roll-dice

Weekly Downloads

39

Version

0.2.2

License

MIT OR Apache-2.0

Unpacked Size

60 kB

Total Files

7

Last publish

Collaborators

  • jprochazk