Skip to content

Commit

Permalink
normalizeArgument
Browse files Browse the repository at this point in the history
  • Loading branch information
alxjrvs committed Sep 20, 2024
1 parent 03dfca9 commit 8c3def7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/parameterizeRollArgument/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { RandsumRollArgument, RandsumRollParameters } from '~types'
import { D } from '~src/D'
import { formatDescription } from '~utils/formatDescription'
import { formatNotation } from '~utils/formatNotation'
import { parseIntoRollOptions } from './parseIntoRollOptions'
import { normalizeArgument } from './normalizeArgument'

function parameterizeRollArgument(
argument: RandsumRollArgument
): RandsumRollParameters {
const options = parseIntoRollOptions(argument)
const options = normalizeArgument(argument)
const die = new D(options.sides)
return {
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import {
import { RandsumRollArgument, RandsumRollOptions } from '~types'
import { parseNotation } from '~utils/parseNotation'

function parseIntoRollOptions(
argument: RandsumRollArgument
): RandsumRollOptions {
function normalizeArgument(argument: RandsumRollArgument): RandsumRollOptions {
if (isD(argument)) {
return {
quantity: 1,
Expand All @@ -25,19 +23,17 @@ function parseIntoRollOptions(
return parseNotation(argument)
}

const defaultQuantity = 1

if (Array.isArray(argument)) {
return {
quantity: defaultQuantity,
quantity: 1,
sides: argument.map(String)
}
}

return {
quantity: defaultQuantity,
quantity: 1,
sides: Number(argument || 20)
}
}

export { parseIntoRollOptions }
export { normalizeArgument }

0 comments on commit 8c3def7

Please sign in to comment.