Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fullpipe/ts-dice-math
D&D math for dice rolling.
https://github.com/fullpipe/ts-dice-math
dice dice-roller dnd dnd-tools dnd5e dnd5e-tools
Last synced: about 4 hours ago
JSON representation
D&D math for dice rolling.
- Host: GitHub
- URL: https://github.com/fullpipe/ts-dice-math
- Owner: fullpipe
- License: mit
- Created: 2021-10-03T17:09:42.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-14T14:08:29.000Z (about 3 years ago)
- Last Synced: 2024-11-13T06:33:33.540Z (7 days ago)
- Topics: dice, dice-roller, dnd, dnd-tools, dnd5e, dnd5e-tools
- Language: TypeScript
- Homepage: https://dice-math.fullpipe.dev
- Size: 103 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-dice-math
D&D math for dice rolling. See demo [https://dice-math.fullpipe.dev/](https://dice-math.fullpipe.dev/)
## Install
```bash
npm install ts-dice-math --save
```### Browser (tested with Angular)
You have to install `crypto-browserify`
```bash
npm intall --save crypto-browserify stream-browserify assert stream-http https-browserify os-browserify
```and then add following to your `tsconfig.json`
```jsonp
{
...
"compilerOptions": {
...
"paths": {
"crypto": ["./node_modules/crypto-browserify"],
"stream": ["./node_modules/stream-browserify"],
"assert": ["./node_modules/assert"],
"http": ["./node_modules/stream-http"],
"https": ["./node_modules/https-browserify"],
"os": ["./node_modules/os-browserify"]
}
}
}
```## Usage
```typescript
import { roll } from 'ts-dice-math';...
// roll d20 with advantage
console.log(roll('adv(d20, d20)'));// roll d20 with disadvantage
console.log(roll('dis(d20, d20)'));// roll your two-handed sword damage
console.log(roll('2d6 + 3'));// roll useless things
console.log(roll('d100 / 3 + adv(d20, d20) * 2 - dis(d100, d100, d6)'));
```## What's included
| name | description |
| ---- | ----------- |
| `+`, `-`, `*`, `/` | simple math |
| `d20`, `3d6`, `d12 + d8` | dice rolls |
| `adv(d20, d20)`, `adv(d20 + 3, d20 + 3)` | Advantage. Roll two `d20` and choose best |
| `dis(d20, d20) + 3`, `dis(d20 + 3, d20 + 3)` | Disadvantage. Roll two `d20` and choose worst |## Todo
- [ ] add more useful functions
- [ ] add validation
- [ ] add useful error messages with position of an errorFeel free to contribute.