KScript docs
EN

config fields and methods

$config: settings from config files, .env files and the environment.

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

From KScript.Core

#config->all() → map

Every setting, as a map.
Example
<config defaults="{ server: { port: 8080 } }" />
<echo>{ $config->all() }</echo>
config(defaults: { server: { port: 8080 } })
echo $config->all()

#config->environment() → string

The environment the settings are for (staging, production), or null.
Example
<echo>{ $config->environment() }</echo>
echo $config->environment()

#config->get(path, default?) → any

A setting by path (database.port, servers.0.name), or default when it isn't set.

Arguments can be named: ->get(…, default: …).

Example
<echo>{ $config->get('server.port', 8080) }</echo>
echo $config->get('server.port', 8080)

#config->has(path) → bool

True when the setting is set.
Example
<echo>{ $config->has('database.url') }</echo>
echo $config->has('database.url')

#config->reload() → config

Reads the files again.
Example
<echo>{ $config->reload()->get('server.port', 8080) }</echo>
echo $config->reload()->get('server.port', 8080)

#config->require(path) → any

A setting that must be set: fails with a clear message when it isn't.
Example
<config defaults="{ app: { name: 'Shop' } }" />
<echo>{ $config->require('app.name') }</echo>
config(defaults: { app: { name: 'Shop' } })
echo $config->require('app.name')

#config->sources() → list

The files the settings came from, in order: a list of { name, path, kind }.
Example
<echo>{ $config->sources()->count() >= 0 }</echo>
echo $config->sources()->count() >= 0

Methods from any