Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/one20/tabletop-dice
Dice is a javascript module that provides helper functions to simulate various dice types used in tabletop games.
https://github.com/one20/tabletop-dice
dice es6 javascript mocha polyhedral
Last synced: 2 months ago
JSON representation
Dice is a javascript module that provides helper functions to simulate various dice types used in tabletop games.
- Host: GitHub
- URL: https://github.com/one20/tabletop-dice
- Owner: one20
- Created: 2019-04-08T22:09:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T17:44:44.000Z (almost 2 years ago)
- Last Synced: 2024-04-26T13:03:02.475Z (8 months ago)
- Topics: dice, es6, javascript, mocha, polyhedral
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/tabletop-dice
- Size: 38.1 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dice
## Contents
* [Summary](#summary)
* [Methods](#methods)
* [Usage](#usage)## Summary
`Dice` is a module that provides helper functions to simulate various
dice types used in tabletop games. This is the engine running [diceroll.fun](https://www.diceroll.fun).## Methods
| **roll**( maxValue:```integer```, quantity:```integer```=1 ):```integer/array``` |
| :---------------------------------------------------------------------------- |
| Returns a random integer from 1 to the specified `maxValue`. If a `quantity` is supplied, an array of these random values will be provided with the same length as `quantity`|| **d4**(quantity:```integer```=1 ):```integer/array``` |
| :---------------------------------------------------------------------------- |
| Returns a random integer from **1 to 4**. If a `quantity` is supplied, an array of these random values will be provided with the same length as `quantity`|| **d6**(quantity:```integer```=1 ):```integer/array``` |
| :---------------------------------------------------------------------------- |
| Returns a random integer from **1 to 6**. If a `quantity` is supplied, an array of these random values will be provided with the same length as `quantity`|| **d8**(quantity:```integer```=1 ):```integer/array``` |
| :---------------------------------------------------------------------------- |
| Returns a random integer from **1 to 8**. If a `quantity` is supplied, an array of these random values will be provided with the same length as `quantity`|| **d10**(quantity:```integer```=1 ):```integer/array``` |
| :---------------------------------------------------------------------------- |
| Returns a random integer from **1 to 10**. If a `quantity` is supplied, an array of these random values will be provided with the same length as `quantity`|| **d12**(quantity:```integer```=1 ):```integer/array``` |
| :---------------------------------------------------------------------------- |
| Returns a random integer from **1 to 12**. If a `quantity` is supplied, an array of these random values will be provided with the same length as `quantity`|| **d20**(quantity:```integer```=1 ):```integer/array``` |
| :---------------------------------------------------------------------------- |
| Returns a random integer from **1 to 20**. If a `quantity` is supplied, an array of these random values will be provided with the same length as `quantity`|| **percentage**(quantity:```integer```=1 ):```integer/array``` |
| :---------------------------------------------------------------------------- |
| Returns a random integer from **1 to 100**. If a `quantity` is supplied, an array of these random values will be provided with the same length as `quantity`|| **advantage**():```object``` |
| :---------------------------------------------------------------------------- |
| Returns an object with two properties: `value` & `rolls`. `rolls` is an array of two random integers from **1 to 20** (d20). `value` is an integer equal to the higher of the two numbers in the `rolls` array.|| **disadvantage**():```object``` |
| :---------------------------------------------------------------------------- |
| Returns an object with two properties: `value` & `rolls`. `rolls` is an array of two random integers from **1 to 20** (d20). `value` is an integer equal to the lower of the two numbers in the `rolls` array.|## Usage
```
let Dice = require('tabletop-dice')//Roll a d4
Dice.d4() //Example output: 3//Roll 4 d8's
Dice.d8(4) //Example output: [2,6,3,8]//Roll at advantage
Dice.advantage() //Example output: { value: 14, rolls: [6, 14]}
```