UNPKG

dice-wizard

Version:

A utility package for rolling dice with various configurations

53 lines (52 loc) 1.82 kB
export type DieType = 4 | 6 | 8 | 10 | 12 | 20 | 100; export interface DieResult { value: number; dieType: DieType; } export declare class DiceWizard { private results; /** * Roll dice using either string notation (e.g. 'd20', '3d6') or number parameters * @param countOrNotation Number of dice or string notation * @param dieType Type of die (optional if using string notation) * @returns Array of die results */ roll(countOrNotation: number | string, dieType?: DieType): DieResult[]; private isValidDieType; /** * Get the sum of the last roll * @returns Total value of all dice in last roll */ getSum(): number; /** * Filter dice from the last roll based on their values * @param predicate Function to determine which dice to keep * @returns Filtered array of die results */ filterDice(predicate: (die: DieResult) => boolean): DieResult[]; /** * Keep only dice with specific values from the last roll * @param values Array of values to keep * @returns Filtered array of die results */ keepValues(values: number[]): DieResult[]; /** * Remove dice with specific values from the last roll * @param values Array of values to remove * @returns Filtered array of die results */ removeValues(values: number[]): DieResult[]; /** * Get the highest N dice from the last roll * @param count Number of dice to keep * @returns Array of the highest value die results */ keepHighest(count: number): DieResult[]; /** * Get the lowest N dice from the last roll * @param count Number of dice to keep * @returns Array of the lowest value die results */ keepLowest(count: number): DieResult[]; } export default DiceWizard;