Skip to content

drawGuarded

Jason Godesky edited this page Jul 19, 2026 · 1 revision

drawGuarded is a wrapper that draws from a roll table and returns the first result if it passes a given type guard. If it doesn’t, it returns the fallback instead.

Parameters

uuid: string

The UUID of the roll table you want to roll on (should begin with RollTable.).

guard: (candidate: unknown) => candidate is T

The type guard to apply against the drawn value.

fallback: T

The fallback to return if the drawn item does not pass the guard.

field: 'name' | 'description'

Whether the value should be pulled from the result’s name or description.

Default: description

Examples

import { drawGuarded } from '@revolutionarygamesco/common-foundryvtt'
import { makeEnum } from '@revolutionarygamesco/common'

const options = ['a', 'b', 'c'] as const
export type TestOption = typeof options[number]
export const {
  guard: isTestOption,
  randomizer: selectRandomTestOption
} = makeEnum(options)

/**
 * This will draw a result from RollTable.1111111111111111,
 * and if its description is a, b, or c, return it. If it’s
 * anything else, this will return the fallback option, a.
 */
drawGuarded('RollTable.1111111111111111', isTestOption, 'a')

Clone this wiki locally