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
npm install @randsum/5e
# or
yarn add @randsum/5e
# or
bun add @randsum/5e
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.
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).
const success = meetOrBeat5e(15, {
modifier: 5,
rollingWith: 'Advantage'
})
// Returns true if roll + modifier meets or exceeds 15
- @randsum/dice: Core dice rolling implementation
- @randsum/notation: Dice notation parser
Made with 👹 by RANDSUM