Config

Config

Constructor

Creates a new configuration instance based on the provided schema.

Parameters

schema: A schema object that defines the configuration schema using the provided methods.

Example

const config = new Config({
  port: Config.string(),
  nested: Config.object({
    foo: Config.string(),
  }),
})

parse

Parses and validate the configuration against the schema.

Parameters

config: An object containing the configuration values to be parsed.

Example

config.parse({ port: 3000, nested: { foo: 'bar' } })

get

Retrieves the value of a specific configuration key.

Parameters

path: The configuration key to retrieve.

Example

config.get('port') // 3000
config.get('nested.foo') // bar

getAll

Returns an object containing all configuration values.

Example

config.getAll('port') // { port: 3000, nested: { foo: 'bar' } }