@randsum/5e
Version:
A flexible, type-safe dice roller for building 5e-compatible applications
95 lines (72 loc) âĸ 2.53 kB
Markdown
<div align="center">
<img width="150" height="150" src="https://raw.githubusercontent.com/RANDSUM/randsum/main/icon.webp">
<h1>@randsum/5e</h1>
<h3>5th Edition compatible dice rolling for randsum</h3>
[](https://www.npmjs.com/package/@randsum/5e)
[](https://bundlephobia.com/package/@randsum/5e)
[](https://www.npmjs.com/package/@randsum/5e)
[](https://github.com/RANDSUM/randsum/blob/main/LICENSE)
[](https://www.npmjs.com/package/@randsum/5e)
</div>
A type-safe implementation of 5th Edition dice rolling mechanics that supports:
- đ˛ Standard d20 rolls with advantage/disadvantage
- đ¯ Automatic handling of modifiers
- đ Full TypeScript support
- đŽ Perfect for 5e compatible applications
- đĒļ Tree-shakeable implementation
```bash
npm install @randsum/5e
yarn add @randsum/5e
bun add @randsum/5e
```
```typescript
import { roll5e, meetOrBeat5e } from '@randsum/5e'
import type { RollArgument5e } from '@randsum/5e'
// Basic roll with modifier
roll5e({ modifier: 5 })
// Roll with advantage
roll5e({
modifier: 5,
rollingWith: 'Advantage'
})
// Roll with disadvantage
roll5e({
modifier: -2,
rollingWith: 'Disadvantage'
})
// Check if roll meets or beats DC
const roll: RollArgument5e = {
modifier: 5,
rollingWith: 'Advantage'
}
meetOrBeat5e(15, roll) // Returns true if roll meets or exceeds DC 15
```
Makes a d20 roll following 5th Edition rules.
```typescript
const result = roll5e({
modifier: 5, // the result of your bonuses after all bonuses are applied
rollingWith: 'Advantage' // Optional
})
// Returns a roll result with total and details
```
Checks if a roll meets or exceeds a Difficulty Class (DC).
```typescript
const success = meetOrBeat5e(15, {
modifier: 5,
rollingWith: 'Advantage'
})
// Returns true if roll + modifier meets or exceeds 15
```
- [@randsum/dice](https://github.com/RANDSUM/randsum/tree/main/packages/dice): Core dice rolling implementation
- [@randsum/notation](https://github.com/RANDSUM/randsum/tree/main/packages/notation): Dice notation parser
<div align="center">
Made with đš by <a href="https://github.com/RANDSUM">RANDSUM</a>
</div>