UNPKG

@randsum/dice

Version:

A flexible, type-safe dice roller for tabletop RPGs, game development, and probability simulations

13 lines (10 loc) 293 B
function calculateTotal( rolls: (string | number)[], bonus: string | number = 0 ): string | number { if (rolls.every((roll) => typeof roll === 'number')) { return rolls.reduce((acc, cur) => Number(acc) + cur, bonus) } return rolls.flat().join(', ') } export { calculateTotal }