From 945534d85d0c312277ade33f9c53845f3831f287 Mon Sep 17 00:00:00 2001 From: emkis Date: Sun, 15 May 2022 02:19:16 -0300 Subject: [PATCH] feat(configuration): add configuration module closes #19 --- src/configuration/configuration.ts | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/configuration/configuration.ts diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts new file mode 100644 index 0000000..a9956b9 --- /dev/null +++ b/src/configuration/configuration.ts @@ -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) { + 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