Configuration class
Configuration implements the IConfiguration interface and adds helper methods for setting values, layering sources, and getting type checked values.
Constructors
| Configuration(Record<string, unknown>) | Create a configuration instance |
Methods
| argv(string[]) | Load process.arguments as a configuration source. |
| bind(string[]) | Bind a path to a Configuration instance such that calls to get or set will automatically include the bound path as a prefix. |
| bool(string[]) | Get a boolean value from config |
| env(string) | Load environment variables as a configuration source. |
| file(string, boolean) | Load a file as a configuration source. |
| get<T>(string[]) | Get a value by path. |
| set(string[], unknown) | Set a value by path. |
| string(string[]) | Get a string value from config |
| type<T>(string[], Zod |
Get a typed value from config |
Constructor Details
Configuration(Record<string, unknown>)
Create a configuration instance
new Configuration(initialValues?: Record<string, unknown>)
Parameters
- initialValues
-
Record<string, unknown>
Optional set of default values to provide
Method Details
argv(string[])
Load process.arguments as a configuration source.
function argv(argv?: string[]): this
Parameters
- argv
-
string[]
arguments to parse, defaults to process.argv
Returns
this
this for chaining
bind(string[])
Bind a path to a Configuration instance such that calls to get or set will automatically include the bound path as a prefix.
function bind(path: string[]): Configuration
Parameters
- path
-
string[]
path to bind to new Configuration instance
Returns
configuration instance with path bound as a prefix
bool(string[])
Get a boolean value from config
function bool(path: string[]): boolean
Parameters
- path
-
string[]
path to boolean value
Returns
boolean
true or false depending on flag
env(string)
Load environment variables as a configuration source.
function env(separator?: string): this
Parameters
- separator
-
string
value used to indicate nesting
Returns
this
this for chaining
file(string, boolean)
Load a file as a configuration source.
function file(name: string, override?: boolean): this
Parameters
- name
-
string
file name
- override
-
boolean
optional flag that ensures this file takes precedence over other files
Returns
this
this for chaining
get<T>(string[])
Get a value by path.
function get<T>(path?: string[]): T | undefined
Parameters
- path
-
string[]
path to value
Returns
T | undefined
the value, or undefined
set(string[], unknown)
Set a value by path.
function set(path: string[], value: unknown)
Parameters
- path
-
string[]
path to value
- value
-
unknown
value to set
string(string[])
Get a string value from config
function string(path: string[]): string | undefined
Parameters
- path
-
string[]
path to string value
Returns
string | undefined
the string or undefined
type<T>(string[], ZodType<T>)
Get a typed value from config
function type<T>(path: string[], t: ZodType<T>): T | undefined
Parameters
- path
-
string[]
path to value
- t
-
ZodType<T>
zod type to use for type checking
Returns
T | undefined
the value, or undefined