Skip to content

Commit

Permalink
Ease of export
Browse files Browse the repository at this point in the history
  • Loading branch information
alxjrvs committed Dec 4, 2024
1 parent a1d7ae1 commit 76c3ba0
Show file tree
Hide file tree
Showing 28 changed files with 58 additions and 31 deletions.
4 changes: 2 additions & 2 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import dts from 'bun-plugin-dts'

const results = await Bun.build({
entrypoints: [
'./src/core/index.ts',
'./src/dice/index.ts',
'./src/faces/index.ts',
'./src/notation/index.ts',
'./src/tower/index.ts',
'./src/types.ts'
'./src/tower/index.ts'
],
outdir: './dist',
splitting: true,
Expand Down
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './types'
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'bun:test'
import { configToDescription } from '~src/utils/configToDescription'
import { configToDescription } from '~src/core/utils/configToDescription'

describe('configToDescription', () => {
test('returns an array strings matching the constraints', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'bun:test'
import { coreRandom } from '~src/utils/coreRandom'
import { coreRandom } from '~src/core/utils/coreRandom'

describe('coreRandom', () => {
test('it returns an object between 1 and the provided number', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from 'bun:test'
import { rollDicePools } from '~src/utils/rollDicePools'
import { DicePoolLike } from '~types'
import { rollDicePools } from '~src/core/utils/rollDicePools'
import { DicePoolLike } from '~src/core/types'

describe('rollDicePools', () => {
test('rolls the provided dice a number of times equal to the quantity', () => {
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions src/core/utils/rollDicePools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { DicePoolLike, DicePoolRollReturn } from '~src/core/types'

export function rollDicePools<R>(
dicePools: DicePoolLike<R>
): DicePoolRollReturn<R> {
return Object.fromEntries(
Object.keys(dicePools).map((key) => {
const {
die,
config: { quantity }
} = dicePools[key]
return [key, die.rollMany(quantity)]
})
)
}
4 changes: 2 additions & 2 deletions src/dice/D.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { coreRandom } from '~src/utils/coreRandom'
import { RollConfig } from '~types'
import { coreRandom } from '~src/core/utils/coreRandom'
import { RollConfig } from '~src/core/types'

export class D {
constructor(public sides: number) {
Expand Down
2 changes: 1 addition & 1 deletion src/faces/rollCustomFaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
CustomFacesDicePools
} from './types'
import { argumentToCustomFacesRollParameters } from './utils/argumentToCustomFacesRollParameters'
import { rollDicePools } from '~src/utils/rollDicePools'
import { rollDicePools } from '~src/core/utils/rollDicePools'

export function rollCustomFaces(
...args: CustomFacesRollArgument[]
Expand Down
2 changes: 1 addition & 1 deletion src/faces/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollConfig } from '~types'
import { RollConfig } from '~src/core/types'
import { NotationValidationResult } from '~src/notation/types'
import { RollArgument } from '~src/tower/types'
import type { CustomFacesD } from './customFacesD'
Expand Down
2 changes: 1 addition & 1 deletion src/faces/utils/customFacesConfigToDescription.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatCoreDescriptions } from '~src/utils/configToDescription'
import { formatCoreDescriptions } from '~src/core/utils/configToDescription'
import type { CustomFacesRollConfig } from '../types'

export function customFacesConfigToDescriptions({
Expand Down
2 changes: 1 addition & 1 deletion src/notation/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollConfig } from '~types'
import { RollConfig } from '~src/core/types'

export interface NotationValidationResult<V = boolean> {
valid: V
Expand Down
2 changes: 1 addition & 1 deletion src/notation/utils/configToNotation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
formatModifierNotation
} from './notationFormatters'
import type { DiceNotation } from '../../types'
import { RollConfig } from '~types'
import { RollConfig } from '~src/core/types'

export function configToNotation(options: RollConfig): DiceNotation {
return `${formatCoreNotation(options)}${formatModifierNotation(options)}`
Expand Down
2 changes: 1 addition & 1 deletion src/notation/utils/configToNotation/notationFormatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
RerollOptions,
UniqueOptions,
RollConfig
} from '~types'
} from '~src/core/types'
import { DiceNotation } from '~src/notation/types'

function capNotation(cap: GreaterLessOptions) {
Expand Down
2 changes: 1 addition & 1 deletion src/notation/utils/notationToRollConfig/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parseCoreNotation, parseModifiers } from './optionsParsers'
import { coreNotationPattern } from '../../patterns'
import { RollConfig } from '~types'
import { RollConfig } from '~src/core/types'
import { DiceNotation } from '~src/notation/types'

export function notationToRollConfig(notationString: DiceNotation): RollConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/notation/utils/notationToRollConfig/optionsParsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Modifiers,
RequiredCoreDiceParameters,
RerollOptions
} from '~types'
} from '~src/core/types'
import {
dropHighestPattern,
dropLowestPattern,
Expand Down
2 changes: 1 addition & 1 deletion src/notation/validateNotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isDiceNotation } from './guards'
import { NotationValidationResult } from './types'
import { notationToRollConfig } from './utils/notationToRollConfig'
import { configToNotation } from './utils/configToNotation'
import { configToDescription } from '~src/utils/configToDescription'
import { configToDescription } from '~src/core/utils/configToDescription'

function validateNotation(arg: string): NotationValidationResult {
if (!isDiceNotation(arg)) {
Expand Down
2 changes: 1 addition & 1 deletion src/tower/__tests__/utils/applyModifiers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, spyOn, test } from 'bun:test'
import { Modifiers } from '~types'
import { Modifiers } from '~src/core/types'
import { D } from '~src/dice/D'
import { RollParameters } from '~src/tower/types'
import {
Expand Down
2 changes: 1 addition & 1 deletion src/tower/roll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { v4 as uuid } from 'uuid'
import type { DicePools, RollArgument, RollResult } from './types'
import { applyModifiers, calculateTotal } from './utils/applyModifiers'
import { argumentToRollParameters } from './utils/argumentToRollParameters'
import { rollDicePools } from '~src/utils/rollDicePools'
import { rollDicePools } from '~src/core/utils/rollDicePools'

export function roll(...args: RollArgument[]): RollResult {
const dicePools = args.reduce(
Expand Down
2 changes: 1 addition & 1 deletion src/tower/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollConfig } from '~types'
import { RollConfig } from '~src/core/types'
import { D } from '~src/dice/D'
import { DiceNotation } from '~src/notation/types'

Expand Down
2 changes: 1 addition & 1 deletion src/tower/utils/applyModifiers/modifierApplicators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ReplaceOptions,
RequiredCoreDiceParameters,
RerollOptions
} from '~types'
} from '~src/core/types'

export class InvalidUniqueError extends Error {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion src/tower/utils/argumentToRollConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollConfig } from '~types'
import { RollConfig } from '~src/core/types'
import { isRollConfigArgument, isD } from '../guards'
import type { RollArgument } from '../types'
import { isDiceNotation } from '~src/notation/guards'
Expand Down
2 changes: 1 addition & 1 deletion src/tower/utils/argumentToRollParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isD } from '../guards'
import type { RollArgument, RollParameters } from '../types'
import { argumentToRollConfig } from './argumentToRollConfig'
import { configToNotation } from '~src/notation/utils/configToNotation'
import { configToDescription } from '~src/utils/configToDescription'
import { configToDescription } from '~src/core/utils/configToDescription'

export function argumentToRollParameters(
argument: RollArgument
Expand Down
2 changes: 1 addition & 1 deletion src/utils/rollDicePools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DicePoolLike, DicePoolRollReturn } from '~types'
import { DicePoolLike, DicePoolRollReturn } from '~src/core/types'

export function rollDicePools<R>(
dicePools: DicePoolLike<R>
Expand Down
25 changes: 18 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
{
"compilerOptions": {
"paths": {
"~models": ["./src/models/index.ts"],
"~patterns": ["./src/patterns.ts"],
"~guards": ["./src/guards.ts"],
"~types": ["./src/types.ts"],
"~src/*": ["./src/*"]
"~models": [
"./src/models/index.ts"
],
"~patterns": [
"./src/patterns.ts"
],
"~guards": [
"./src/guards.ts"
],
"~src/*": [
"./src/*"
]
},
"lib": ["ESNext"],
"lib": [
"ESNext"
],
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
Expand All @@ -21,6 +30,8 @@
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": false,
"types": ["bun-types"]
"types": [
"bun-types"
]
}
}

0 comments on commit 76c3ba0

Please sign in to comment.