@randsum/notation
Version:
Dice notation parser and types for the @randsum ecosystem
25 lines (18 loc) • 554 B
text/typescript
import { type NotationSchema, defineNotationSchema } from '../schema'
const multiplyPattern = /(?<!\*)\*(?!\*)(\d+)/
export const multiplySchema: NotationSchema<number> = defineNotationSchema<number>({
name: 'multiply',
priority: 85,
pattern: multiplyPattern,
parse: notation => {
const match = multiplyPattern.exec(notation)
if (!match) return {}
return { multiply: Number(match[1]) }
},
toNotation: options => {
return `*${options}`
},
toDescription: options => {
return [`Multiply dice by ${options}`]
}
})