You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/www/content/docs/arkenv/index.mdx
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ description: Introducing ArkEnv, an environment variable validator that stays ou
6
6
At its core, ArkEnv is a single export that creates a ready-to-use, typesafe environment variable object:
7
7
8
8
```ts twoslash
9
+
// @noErrors
9
10
importarkenvfrom"arkenv";
10
11
11
12
const env =arkenv({
@@ -19,7 +20,10 @@ const env = arkenv({
19
20
const host =env.HOST;
20
21
const port =env.PORT;
21
22
const nodeEnv =env.NODE_ENV;
22
-
const debugging =env.DEBUGGING;
23
+
24
+
// Type "env." to see autocomplete
25
+
const debugging =env.
26
+
// ^|
23
27
```
24
28
25
29
> ArkEnv defaults to [ArkType](https://arktype.io/) notation, the closest match to TypeScript syntax for editor-to-runtime typesafety. You can also use any [Standard Schema](https://standardschema.dev/schema) validator, including Zod, Valibot, and Typia.
You can pass a custom object instead of `process.env`. This is particularly useful in environments like Cloudflare Workers where variables are passed via a context object, or when testing.
15
21
16
22
```ts twoslash
17
23
importarkenvfrom"arkenv";
@@ -22,9 +28,9 @@ const env = arkenv(
22
28
);
23
29
```
24
30
25
-
##`coerce`
31
+
### Disabling coercion
26
32
27
-
Whether to coerce environment variables to their defined types. Defaults to `true`.
33
+
By default, ArkEnv automatically coerces string environment variables to numbers or booleans if the schema requires it. You can disable this behavior:
28
34
29
35
```ts twoslash
30
36
importarkenvfrom"arkenv";
@@ -37,20 +43,9 @@ const env = arkenv(
37
43
38
44
See the [coercion docs](/docs/arkenv/coercion) for more details.
39
45
40
-
## `onUndeclaredKey`
41
-
42
-
Control how ArkEnv handles environment variables that are not defined in your schema. Defaults to `"delete"`.
46
+
### Custom array format
43
47
44
-
-`"delete"` — Undeclared keys are allowed on input but stripped from the output.
45
-
-`"ignore"` — Undeclared keys are allowed and preserved in the output.
46
-
-`"reject"` — Undeclared keys will cause validation to fail.
47
-
48
-
## `arrayFormat`
49
-
50
-
The format to use for array parsing when coercion is enabled. Defaults to `"comma"`.
51
-
52
-
-`"comma"` — Strings are split by comma and trimmed.
53
-
-`"json"` — Strings are parsed as JSON.
48
+
When coercion is enabled, you can specify how array strings are parsed.
54
49
55
50
```ts twoslash
56
51
importarkenvfrom"arkenv";
@@ -61,11 +56,9 @@ const env = arkenv(
61
56
);
62
57
```
63
58
64
-
## `emptyAsUndefined`
65
-
66
-
Whether to treat empty strings (`""`) as `undefined` before validation. Defaults to `false`.
59
+
### Empty strings as undefined
67
60
68
-
When enabled, an environment variable set to an empty value (e.g., `PORT=` in a `.env` file) will be treated as if it were missing, allowing defaults to apply and preventing validation errors for numeric or boolean types.
61
+
When `emptyAsUndefined` is enabled, an environment variable set to an empty value (e.g., `PORT=` in a `.env` file) will be treated as if it were missing. This allows defaults to apply and prevents validation errors for numeric or boolean types.
Copy file name to clipboardExpand all lines: apps/www/content/docs/arkenv/quickstart.mdx
+40-70Lines changed: 40 additions & 70 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,93 +11,63 @@ ArkEnv is tested on [**Next.js** **16.x**](https://github.com/yamcodes/arkenv/tr
11
11
12
12
The easiest way to get started is with the [ArkEnv CLI](/docs/cli). It automatically configures ArkEnv for your project, installs dependencies, and scaffolds your initial schema.
ArkEnv expects **TypeScript >= 5.1** and `strict` mode in your `tsconfig.json`.
46
+
ArkEnv expects **TypeScript >= 5.1** and `strict` mode in your `tsconfig.json`.
73
47
74
-
You're also expected to use a [modern TypeScript module resolution](https://www.typescriptlang.org/tsconfig/#moduleResolution).
48
+
You're also expected to use a [modern TypeScript module resolution](https://www.typescriptlang.org/tsconfig/#moduleResolution).
75
49
76
-
```json title="tsconfig.json"
77
-
// [!code word:config]
78
-
{
79
-
"compilerOptions": {
80
-
"strict": true, // [!code focus]
81
-
"moduleResolution": "bundler"// [!code focus] or "node16" / "nodenext"
82
-
}
83
-
}
84
-
```
50
+
```json title="tsconfig.json"
51
+
// [!code word:config]
52
+
{
53
+
"compilerOptions": {
54
+
"strict": true, // [!code focus]
55
+
"moduleResolution": "bundler"// [!code focus] or "node16" / "nodenext"
56
+
}
57
+
}
58
+
```
85
59
86
-
:::note
87
-
While ArkEnv [can](https://github.com/yamcodes/arkenv/tree/main/examples/basic-js) work with plain JavaScript, TypeScript is strongly recommended for the best experience.
88
-
:::
89
-
</Step>
60
+
:::note
61
+
While ArkEnv [can](https://github.com/yamcodes/arkenv/tree/main/examples/basic-js) work with plain JavaScript, TypeScript is strongly recommended for the best experience.
62
+
:::
90
63
91
-
<Step>
92
-
### Setup ArkType (optional)
64
+
### Setup ArkType (optional) [step][!toc]
93
65
94
-
While ArkEnv [works with any Standard Schema validator](/docs/arkenv/integrations/standard-schema), we
95
-
recommend using ArkType for the ultimate ArkEnv experience.
66
+
While ArkEnv [works with any Standard Schema validator](/docs/arkenv/integrations/standard-schema), we
67
+
recommend using ArkType for the ultimate ArkEnv experience.
96
68
97
-
Follow the [ArkType setup](https://arktype.io/docs/intro/setup) to complete your configuration. We
98
-
recommend installing the ArkType syntax highlighting extension if your IDE supports it.
99
-
</Step>
100
-
</Steps>
69
+
Follow the [ArkType setup](https://arktype.io/docs/intro/setup) to complete your configuration. We
70
+
recommend installing the ArkType syntax highlighting extension if your IDE supports it.
0 commit comments