Skip to content

Commit

Permalink
Rename files, remove unused "as"'s, bump to 6.0.0 (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxjrvs authored Sep 20, 2024
1 parent b748c3f commit 7ee536c
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 57 deletions.
Binary file modified bun.lockb
Binary file not shown.
Empty file removed foo.md
Empty file.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "randsum",
"version": "5.0.0",
"version": "6.0.0",
"private": false,
"author": "Alex Jarvis",
"icon": "https://raw.githubusercontent.com/RANDSUM/randsum-ts/main/icon.webp",
Expand Down
2 changes: 1 addition & 1 deletion src/parameterizeRollArgument/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function parameterizeRollArgument(
die,
notation: formatNotation(options),
description: formatDescription(options)
} as RandsumRollParameters
}
}

export { parameterizeRollArgument }
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ function generateModifiedRolls(
)
}

function generateRollResultFromParameters(
DicePools: DicePools
): RandsumRollResult {
function generateRollResult(DicePools: DicePools): RandsumRollResult {
const rawRolls = generateRawRolls(DicePools.dicePools)
const modifiedRolls = generateModifiedRolls(DicePools, rawRolls)
const modifiedValues = Object.values(modifiedRolls)
Expand All @@ -74,4 +72,4 @@ function generateRollResultFromParameters(
}
}

export { generateRollResultFromParameters }
export { generateRollResult }
4 changes: 2 additions & 2 deletions src/roll/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { RandsumRollArgument, RandsumRollResult } from '~types'
import { generateRollResultFromParameters } from './generateRollResultFromParameters'
import { generateRollResult } from './generateRollResult'
import { formDicePools } from './formDicePools'

function roll(arg?: RandsumRollArgument): RandsumRollResult {
const dicePools = formDicePools(arg)
return generateRollResultFromParameters(dicePools)
return generateRollResult(dicePools)
}

export { roll }
10 changes: 4 additions & 6 deletions src/utils/formatNotation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ function formatModifierNotation({ modifiers }: RandsumRollOptions): string {
}

function formatCoreNotation({
quantity,
quantity = 1,
sides
}: RandsumRollOptions<string | number>) {
}: RandsumRollOptions<string | number>): RandsumNotation {
const formattedSides = Array.isArray(sides)
? `{${sides.map((s) => (s === '' ? ' ' : s)).join('')}}`
: sides
return `${quantity}d${formattedSides}`
return `${quantity}d${formattedSides}` as RandsumNotation
}

function formatNotation(options: RandsumRollOptions): RandsumNotation {
return `${formatCoreNotation(options)}${formatModifierNotation(options)}` as
| RandsumNotation<string>
| RandsumNotation<number>
return `${formatCoreNotation(options)}${formatModifierNotation(options)}` as RandsumNotation
}

export { formatNotation }
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function parseCoreNotation(
sides: sides.includes('{')
? [...sides.replaceAll(/{|}/g, '')]
: Number(sides)
} as RequiredCoreDiceParameters
}
}

function parseCapNotation(modifiersString: string): Pick<Modifiers, 'cap'> {
Expand Down
2 changes: 1 addition & 1 deletion tests/generateRawRolls.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'bun:test'

import { RandsumRollParameters, DicePools } from '~types'
import { generateRawRolls } from '~src/roll/generateRollResultFromParameters/generateRawRolls'
import { generateRawRolls } from '~src/roll/generateRollResult/generateRawRolls'

describe('generateRawRolls', () => {
describe('when given a DicePools object', () => {
Expand Down
76 changes: 35 additions & 41 deletions tests/generateResult.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { describe, expect, spyOn, test } from 'bun:test'

import { D } from '~src/D'
import { generateRollResultFromParameters } from '~src/roll/generateRollResultFromParameters'
import { InvalidUniqueError } from '~src/roll/generateRollResultFromParameters/applyModifiers'
import * as GenerateRawRolls from '~src/roll/generateRollResultFromParameters/generateRawRolls'
import { generateRollResult } from '~src/roll/generateRollResult'
import { InvalidUniqueError } from '~src/roll/generateRollResult/applyModifiers'
import * as GenerateRawRolls from '~src/roll/generateRollResult/generateRawRolls'
import { RandsumNotation, DicePoolType, DicePools } from '~types'

describe('generateRollResultFromParameters', () => {
describe('generateRollResult', () => {
const testRollSet = [1, 2, 3, 4]
const coreRawRolls = {
'test-roll-id': testRollSet
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('generateRollResultFromParameters', () => {
coreRawRolls
)

expect(generateRollResultFromParameters(coreParameters)).toMatchObject({
expect(generateRollResult(coreParameters)).toMatchObject({
...coreParameters,
rawRolls: coreRawRolls,
type: DicePoolType.standard,
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('generateRollResultFromParameters', () => {
}
spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(rawRolls)

expect(generateRollResultFromParameters(uniqueParameters)).toMatchObject({
expect(generateRollResult(uniqueParameters)).toMatchObject({
...uniqueParameters,
rawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -116,9 +116,7 @@ describe('generateRollResultFromParameters', () => {
rawRolls
)

expect(
generateRollResultFromParameters(notUniqueParameters)
).toMatchObject({
expect(generateRollResult(notUniqueParameters)).toMatchObject({
...notUniqueParameters,
rawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -162,9 +160,9 @@ describe('generateRollResultFromParameters', () => {
rawRolls
)

expect(() =>
generateRollResultFromParameters(overflowParameters)
).toThrow(new InvalidUniqueError())
expect(() => generateRollResult(overflowParameters)).toThrow(
new InvalidUniqueError()
)
})
})
})
Expand Down Expand Up @@ -194,9 +192,7 @@ describe('generateRollResultFromParameters', () => {
}
spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(rawRolls)

expect(
generateRollResultFromParameters(customSidesParameters)
).toMatchObject({
expect(generateRollResult(customSidesParameters)).toMatchObject({
...customSidesParameters,
rawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -245,7 +241,7 @@ describe('generateRollResultFromParameters', () => {
}
spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(rawRolls)

expect(generateRollResultFromParameters(dropParameters)).toMatchObject({
expect(generateRollResult(dropParameters)).toMatchObject({
...dropParameters,
rawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -284,7 +280,7 @@ describe('generateRollResultFromParameters', () => {
coreRawRolls
)

expect(generateRollResultFromParameters(dropParameters)).toMatchObject({
expect(generateRollResult(dropParameters)).toMatchObject({
...dropParameters,
rawRolls: coreRawRolls,
type: DicePoolType.standard,
Expand Down Expand Up @@ -327,7 +323,7 @@ describe('generateRollResultFromParameters', () => {
coreRawRolls
)

expect(generateRollResultFromParameters(dropParameters)).toMatchObject({
expect(generateRollResult(dropParameters)).toMatchObject({
...dropParameters,
type: DicePoolType.standard,
rawRolls: coreRawRolls,
Expand Down Expand Up @@ -369,21 +365,19 @@ describe('generateRollResultFromParameters', () => {
}
spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(rawRolls)

expect(generateRollResultFromParameters(explodeParameters)).toMatchObject(
{
...explodeParameters,
rawRolls,
type: DicePoolType.standard,
modifiedRolls: {
'test-roll-id': {
rolls: [1, 2, 3, 6, 200],
total: 212
}
},
total: 212,
result: [[1, 2, 3, 6, 200]]
}
)
expect(generateRollResult(explodeParameters)).toMatchObject({
...explodeParameters,
rawRolls,
type: DicePoolType.standard,
modifiedRolls: {
'test-roll-id': {
rolls: [1, 2, 3, 6, 200],
total: 212
}
},
total: 212,
result: [[1, 2, 3, 6, 200]]
})
})
})

Expand All @@ -409,7 +403,7 @@ describe('generateRollResultFromParameters', () => {
spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(
coreRawRolls
)
expect(generateRollResultFromParameters(reDicePools)).toMatchObject({
expect(generateRollResult(reDicePools)).toMatchObject({
...reDicePools,
rawRolls: coreRawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -448,7 +442,7 @@ describe('generateRollResultFromParameters', () => {
spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(
coreRawRolls
)
expect(generateRollResultFromParameters(reDicePools)).toMatchObject({
expect(generateRollResult(reDicePools)).toMatchObject({
...reDicePools,
rawRolls: coreRawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -487,7 +481,7 @@ describe('generateRollResultFromParameters', () => {
spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(
coreRawRolls
)
expect(generateRollResultFromParameters(reDicePools)).toMatchObject({
expect(generateRollResult(reDicePools)).toMatchObject({
...reDicePools,
rawRolls: coreRawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -525,7 +519,7 @@ describe('generateRollResultFromParameters', () => {
spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(
coreRawRolls
)
expect(generateRollResultFromParameters(dropParameters)).toMatchObject({
expect(generateRollResult(dropParameters)).toMatchObject({
...dropParameters,
rawRolls: coreRawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -562,7 +556,7 @@ describe('generateRollResultFromParameters', () => {
spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(
coreRawRolls
)
expect(generateRollResultFromParameters(dropParameters)).toMatchObject({
expect(generateRollResult(dropParameters)).toMatchObject({
...dropParameters,
rawRolls: coreRawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -598,7 +592,7 @@ describe('generateRollResultFromParameters', () => {
spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(
coreRawRolls
)
expect(generateRollResultFromParameters(dropParameters)).toMatchObject({
expect(generateRollResult(dropParameters)).toMatchObject({
...dropParameters,
rawRolls: coreRawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -640,7 +634,7 @@ describe('generateRollResultFromParameters', () => {
}

spyOn(GenerateRawRolls, 'generateRawRolls').mockReturnValueOnce(rawRolls)
expect(generateRollResultFromParameters(parameters)).toMatchObject({
expect(generateRollResult(parameters)).toMatchObject({
...parameters,
rawRolls,
modifiedRolls: {
Expand Down Expand Up @@ -678,7 +672,7 @@ describe('generateRollResultFromParameters', () => {
} as unknown as DicePools

test('Throws an error', () => {
expect(() => generateRollResultFromParameters(dropParameters)).toThrow(
expect(() => generateRollResult(dropParameters)).toThrow(
'Unknown modifier: foo'
)
})
Expand Down

0 comments on commit 7ee536c

Please sign in to comment.