Skip to content

Configuration

The Config struct controls parsing, interpolation, and serialization behavior.

Config Options

OptionTypeDefaultDescription
trimbooltrueTrim whitespace from keys and values
allow_emptybooltrueAllow empty values (KEY= or KEY="")
interpolatebooltrueEnable variable interpolation (${VAR}, $VAR)
overridebooltrueOverride existing values when loading multiple files
strictboolfalseFail on syntax errors instead of skipping invalid lines
allow_inline_commentsbooltrueAllow inline comments (# comment after value)
allow_multilineboolfalseAllow multiline values (backslash continuation)
max_interpolation_depthusize10Maximum interpolation recursion depth
comment_charu8#Character used for comments
export_to_envboolfalseExport loaded values to the process environment
preserve_commentsboolfalsePreserve comments when serializing
sort_keysboolfalseSort keys alphabetically when serializing
indentusize0Indentation for serialized output (number of spaces)
trailing_newlinebooltrueAdd a trailing newline when writing
quote_spacesbooltrueQuote values that contain spaces when writing

Builder Pattern

Use .with() to create modified configs:

zig
const config = env_mod.Config{};
const strict_config = config.with(.{
    .strict = true,
    .interpolate = false,
    .max_interpolation_depth = 5,
});

Strict Mode

In strict mode, the parser returns error.ParseError on invalid syntax:

zig
var env = env_mod.Env.init(allocator, .{ .strict = true });
try env.parseString("123BAD=value\n"); // Returns error.ParseError

In non-strict mode (default), invalid lines are silently skipped.

Released under the MIT License.