UNPKG

@randsum/roller

Version:

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

18 lines (15 loc) 604 B
import type { ReplaceOptions } from '../../../types' import { formatComparisonNotation } from '../../comparisonUtils' export function formatReplaceNotation( options: ReplaceOptions | ReplaceOptions[] ): string | undefined { const rules = Array.isArray(options) ? options : [options] const notations = rules.map(({ from, to }) => { if (typeof from === 'object') { const comparisons = formatComparisonNotation(from) return comparisons.map(comp => `${comp}=${to}`).join(',') } return `${from}=${to}` }) return notations.length ? `V{${notations.join(',')}}` : undefined }