Skip to content

Commit

Permalink
feat(configuration): add configuration module
Browse files Browse the repository at this point in the history
closes #19
  • Loading branch information
emkis committed May 16, 2022
1 parent 8157e93 commit 945534d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { merge } from 'lodash-es'
import { throwNoConfigurationProvided } from './configuration-errors'
import type { Configurations } from './configuration-types'

export function createConfiguration() {
const configurations: Configurations = defaults()

function defaults(): Configurations {
return {
logger: {
debugAll: false,
debugEvents: false,
debugContext: false,
},
}
}

function get() {
return configurations
}

function configure(customConfigs: Partial<Configurations>) {
const isConfigDefined = Boolean(customConfigs)
if (!isConfigDefined) throwNoConfigurationProvided()
merge(configurations, customConfigs)
}

return { get, defaults, configure }
}

export const configuration = createConfiguration()

/**
* It configures custom behaviors.
* @public
*/
export const { configure } = configuration

0 comments on commit 945534d

Please sign in to comment.