@machb/config / Configurator
Interface: Configurator
Defined in: Configurator.ts:12
Interface for configuration providers.
Implementations should provide methods to retrieve configuration properties as optional or required values, as well as methods to handle array properties.
Configurator
Remarks
This interface defines the contract for configuration providers, allowing flexible retrieval of configuration settings in various formats.
Methods
getArrayProp()
getArrayProp(
name,defaultValue?):string[] |undefined
Defined in: Configurator.ts:65
Retrieve a configuration property and return it as an array of strings, or a default array.
Current behavior: - If a value is found, it is returned as a single-element string array: [value]. - Otherwise, the provided defaultValue is returned (may be undefined).
Parameters
name
string
The property name to retrieve.
defaultValue?
string[]
Default array to return when no value exists.
Returns
string[] | undefined
A string array if a value exists or the provided default; otherwise undefined.
Remarks
This method does not attempt to split comma-separated values. If you need multi-value parsing, split the returned single-element string externally.
optional()
optional(
name,defaultValue?):string|undefined
Defined in: Configurator.ts:25
Retrieve a configuration property as an optional string. If the property is not found, return the provided default value or undefined.
Parameters
name
string
defaultValue?
string
Returns
string | undefined
The property value as a string, or the default value if not found.
Remarks
This method does not throw an error if the property is missing; it simply returns the default value or undefined.
required()
required(
name):string
Defined in: Configurator.ts:38
Retrieve a required configuration property as a string. If the property is not found, this method throws an Error.
Parameters
name
string
The property name to retrieve.
Returns
string
The property value as a string.
Remarks
This method ensures that the requested property is present; otherwise, it raises an error. Use this method when the presence of the property is critical for application functionality.
Throws
Error if the property cannot be resolved.
requiredArray()
requiredArray(
name):string[]
Defined in: Configurator.ts:50
Retrieve a required configuration property as an array of strings. If the property is not found, this method throws an Error.
Parameters
name
string
The property name to retrieve.
Returns
string[]
An array of strings representing the property value.
Remarks
This method treats a single string value as a one-element array. Use this method when the property is expected to have multiple values.
Throws
Error if the property cannot be resolved.