Skip to content

Configuration ​

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

Config Options ​

OptionTypeDefaultDescription
trimbooltrueTrim surrounding whitespace from unquoted values (quoted preserved)
allowEmptybooltrueAllow 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
allowInlineCommentsbooltrueStrip # comment from unquoted values; quoted # is literal
allowMultilineboolfalseBackslash-newline continuation joins the next line
maxInterpolationDepthusize10Maximum interpolation recursion depth (actually enforced)
exportToRuntimeboolfalseExport set/remove via single runtime impl (prefer explicit exportToRuntime())
sortKeysboolfalseSort keys alphabetically when serializing
trailingNewlinebooltrueEmit trailing \n after the last entry
quoteSpacesbooltrueQuote values needing quotes for a lossless round-trip

Builder Pattern ​

Use .with() to create modified configs:

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

Strict Mode ​

In strict mode, the parser returns the specific EnvError for invalid syntax:

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

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

Released under the MIT License.