UNPKG

@randsum/roller

Version:

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

16 lines (12 loc) 494 B
import { isDiceNotation } from '../../isDiceNotation' import { notationToOptions } from '../../lib/notation' import type { RollArgument, RollOptions } from '../../types' export function optionsFromArgument<T>(argument: RollArgument<T>): RollOptions<T>[] { if (isDiceNotation(argument)) { return [...notationToOptions<T>(argument)] } if (typeof argument === 'string' || typeof argument === 'number') { return [{ quantity: 1, sides: Number(argument) }] } return [argument] }