Valibot
Validate environment variables with @arkenv/standard/valibot.
@arkenv/standard/valibot wires Valibot into ArkEnv. Valibot implements
Standard Schema. The subpath pre-configures
@valibot/to-json-schema so
ArkEnv can coerce strings into numbers, booleans, and arrays.
For an overview of engine options, see Validators.
Installation
Install @arkenv/standard, valibot, and the JSON Schema converter (an
optional peer of @arkenv/standard):
npm install @arkenv/standard valibot @valibot/to-json-schemapnpm add @arkenv/standard valibot @valibot/to-json-schemayarn add @arkenv/standard valibot @valibot/to-json-schemabun install @arkenv/standard valibot @valibot/to-json-schemaTypeScript must use moduleResolution: "bundler" | "node16" | "nodenext".
Subpath exports are not resolved under legacy "node" module resolution.
Define your schema
Declare environment variables in an env.ts file using Valibot schemas:
import { } from "@arkenv/standard/valibot";
import * as from "valibot";
export const = ({
: .(.(), .()),
: .(.(), 3000),
: .(.(), false),
: .(.(.()), []),
: .(
.(["development", "production", "test"]),
"development",
),
});Use v.number() and v.boolean() directly. Manual v.transform(Number)
steps are not required.
JSON Schema configuration
Valibot does not embed JSON Schema metadata on schema instances. The
/valibot subpath calls @valibot/to-json-schema with:
typeMode: "input"so piped and transformed schemas are evaluated according to their input types and strings can be coercedtarget: "draft-07"so output matches the JSON Schema draft ArkEnv expects
The root toJsonSchema callback remains available on @arkenv/standard for
custom converters or mixed-validator maps. See
Coercion.
Defaults and optionals
Valibot fallbacks and optionals map onto ArkEnv the same way as other engines:
| Pattern | Behavior |
|---|---|
v.optional(schema, defaultValue) | Fallback value used when the variable is undefined |
v.optional(schema) | Allows the variable to remain undefined |
emptyAsUndefined: true | Converts empty strings ("") to undefined so optional defaults trigger |