options

Configuration object passed as the second argument to arkenv().

Edit on GitHub

The second argument to arkenv() is an optional configuration object. Shared fields exist on both engines: env, coerce, emptyAsUndefined, onUndeclaredKey, arrayFormat, and debugSecrets. safe is reserved for call-site compat (false or omit only). toJsonSchema exists only on @arkenv/standard. ArkType already exposes JSON Schema, so @arkenv/core has nothing to fall back to.

Type

ArkEnvConfig is the ArkType engine table. StandardEnvConfig is that table plus optional toJsonSchema.

Prop

Type

The environment variables to parse. Defaults to process.env.

All values must be strings (or undefined) to match process.env semantics.

Type

Record<string, string | undefined> | undefined

Whether to coerce environment variables to their defined types. Defaults to true

Type

boolean | undefined

Control how ArkEnv handles environment variables that are not defined in your schema.

Defaults to 'delete' so the output object only contains keys you've declared.

  • delete (default): Undeclared keys are allowed on input but stripped from the output.
  • ignore: Undeclared keys are allowed and preserved in the output.
  • reject: Undeclared keys will cause validation to fail.

Type

"ignore" | "delete" | "reject" | undefined

Default

"delete"

The format to use for array parsing when coercion is enabled.

  • comma (default): Strings are split by comma and trimmed.
  • json: Strings are parsed as JSON.

Type

"comma" | "json" | undefined

Default

"comma"

Whether to bypass secret redaction and print raw sensitive values during debugging. Defaults to checking process.env.ARKENV_DEBUG_SECRETS === "true" or "1".

Type

boolean | undefined

Whether to treat empty strings ("") as undefined before validation.

When enabled, an environment variable set to an empty value (e.g. PORT=) will be treated as if it were missing, allowing defaults to apply and preventing validation errors for numeric or boolean types.

Type

boolean | undefined

Default

false

Reserved for call-site compat. Pass false or omit. Use arkenv from @arkenv/core/safe instead of { safe: true }.

Type

false | undefined

Default

false

Options

Each field below is optional. Omit the whole object to read process.env with coercion on.

env

The record to parse. Defaults to process.env. Pass a record in tests, Cloudflare Workers, or when you load values with Vite loadEnv.

./env.ts
import  from "@arkenv/core";

export const  = (
  { : "number.port" },
  { : { : "3000" } },
);

coerce

Default: true

When true, ArkEnv turns env strings into the types in your schema before the validator runs. Turn it off when you want raw strings and you transform them yourself.

./env.ts
import  from "@arkenv/core";

export const  = (
  { : "string" },
  { : false, : { : "3000" } },
);

.; // "3000"

See Coercion and parsing.

arrayFormat

Default: "comma"

How ArkEnv parses array env values when coercion is on.

  • "comma": split on commas and trim each item
  • "json": parse the string as JSON

Use "json" when your host stores arrays as JSON strings.

./env.ts
import  from "@arkenv/core";

export const  = (
  { : "string[]" },
  { : "json", : { : '["web", "app"]' } },
);

emptyAsUndefined

Default: false

An empty assignment in a .env file still sets the key. ArkEnv sees "", so defaults do not apply and non-string types fail:

.env
PORT=
DEBUG=

Set emptyAsUndefined: true to treat empty strings as missing before validation. Then PORT= behaves like an unset key and the default applies:

./env.ts
import  from "@arkenv/core";

export const  = (
  {
    : "number.port = 3000",
    : "boolean = false",
  },
  {
    : true,
    : {
      : "",
      : "",
    },
  },
);

.; // 3000
.; // false

The env option above only simulates a loaded .env for the snippet. In an app, your runner or framework loads .env* into process.env first; you pass { emptyAsUndefined: true } alone.

onUndeclaredKey

Default: "delete"

What to do with keys that appear on input but not in your schema.

  • "delete": allow them on input, strip them from the output
  • "ignore": allow them and keep them on the output
  • "reject": fail validation
./env.ts
import  from "@arkenv/core";

export const  = (
  { : "number.port" },
  {
    : "reject",
    : { : "3000", : "nope" },
  },
);

safe

Default: false

Reserved on the main arkenv() entry. Pass false or omit — { safe: true } is not accepted. For a result object, import arkenv from @arkenv/core/safe or @arkenv/standard/safe.

./env.ts
import  from "@arkenv/core/safe";

const  = (
  { : "number.port" },
  { : { : "invalid" } },
);

if (!.) {
  .(.);
} else {
  .(..);
}

Framework plugins (Next.js, Nuxt, Vite, Bun) do not ship a /safe subpath, so a failed validation cannot soft-fail into the client bundle. Call arkenv from @arkenv/core/safe or @arkenv/standard/safe yourself if you need programmatic failure handling outside a plugin.

debugSecrets

Default: process.env.ARKENV_DEBUG_SECRETS is "true" or "1"

Bypass secret redaction in debug output so you can see raw values. Leave this off in shared logs and CI.

toJsonSchema

@arkenv/standard only. This field is not on ArkType ArkEnvConfig. Vite and Bun /standard plugin configs that alias ParseStandardConfig inherit it.

Pass a fallback converter for Standard Schema validators that omit JSON Schema on the value (Valibot, Zod Mini, Zod v3 via zod-to-json-schema, and similar). ArkEnv calls it per key when it can't read JSON Schema from that value.

Wiring: prefer @arkenv/standard/valibot and @arkenv/standard/zod-mini. The callback remains the escape hatch for Zod v3 and mixed maps. See Coercion.

Framework-only options

Next.js and Nuxt wrappers accept extends to merge shared or client env objects into a server schema. That field lives outside core ArkEnvConfig. See Client vs. server.

Next steps