@randsum/roller
Version:
A flexible, type-safe dice roller for tabletop RPGs, game development, and probability simulations
23 lines (20 loc) • 632 B
text/typescript
import { isDiceNotation } from './isDiceNotation'
import type { ValidationResult } from './types'
import { optionsToDescription, optionsToNotation } from './lib/transformers'
import { notationToOptions } from './lib/notation'
export function validateNotation(notation: string): ValidationResult {
if (!isDiceNotation(notation)) {
return {
valid: false,
argument: notation
}
}
const options = notationToOptions(notation)
return {
valid: true,
argument: notation,
options,
notation: options.map(o => optionsToNotation(o)),
description: options.map(o => optionsToDescription(o))
}
}