@randsum/dice
Version:
A flexible, type-safe dice roller for tabletop RPGs, game development, and probability simulations
15 lines (14 loc) • 527 B
JavaScript
import { calculateTotal, normalizeArgument } from './utils';
import { generateRoll } from './utils/generateRoll';
import { rollType } from './utils/rollType';
function roll(...args) {
const parameters = args.map((arg) => normalizeArgument(arg));
const rolls = parameters.map((param) => generateRoll(param));
return {
rolls,
rawResults: rolls.map((roll) => roll.rawRolls).flat(),
total: calculateTotal(rolls.map((roll) => roll.total)),
type: rollType(rolls)
};
}
export { roll };