@@ -39,7 +39,7 @@ Popular options include:
3939### Type-Safe Validation of Nested Schema
4040
4141``` typescript
42- import { parseEnv , envvar , EnvaseError } from ' envase' ;
42+ import { parseEnv , envvar } from ' envase' ;
4343import { z } from ' zod' ;
4444
4545const config = parseEnv (process .env , {
@@ -49,29 +49,34 @@ const config = parseEnv(process.env, {
4949 },
5050 },
5151 db: {
52- host: envvar (' DB_HOST' , z .string ().min (1 )),
52+ host: envvar (' DB_HOST' , z .string ().min (1 ). default ( ' localhost ' ) ),
5353 },
54- apiKey: envvar (' API_KEY' , z .string ().min (32 )),
54+ apiKey: envvar (' API_KEY' , z .string ().min (32 ). optional () ),
5555});
5656// config.app.listen.port -> number
5757// config.db.host -> string
58- // config.apiKey -> string
58+ // config.apiKey -> string | undefined
5959```
6060
6161### Environment Detection
6262
6363``` typescript
64- const config = parseEnv (process .env , {});
65- // config.isProduction -> boolean
66- // config.isDevelopment -> boolean
67- // config.isTest -> boolean
64+ import { detectNodeEnv } from ' envase' ;
65+
66+ const nodeEnv = detectNodeEnv (process .env );
67+ // nodeEnv.isProduction -> boolean
68+ // nodeEnv.isTest -> boolean
69+ // nodeEnv.isDevelopment -> boolean
6870```
6971
7072These flags are inferred from the ` NODE_ENV ` value (i.e. 'production', 'test', or 'development').
7173
7274### Detailed error reporting
7375
7476``` typescript
77+ import { parseEnv , envvar , EnvaseError } from ' envase' ;
78+ import { z } from ' zod' ;
79+
7580try {
7681 parseEnv (process .env , {
7782 apiKey: envvar (' API_KEY' , z .string ().min (32 )),
@@ -111,6 +116,9 @@ try {
111116### Type Inference
112117
113118``` typescript
119+ import { envvar , type InferEnv } from ' envase' ;
120+ import { z } from ' zod' ;
121+
114122const envSchema = {
115123 apiKey: envvar (' API_KEY' , z .string ().min (32 )),
116124 db: {
@@ -135,8 +143,17 @@ This helps pair the raw env name with the shape you expect it to conform to.
135143
136144` parseEnv(env: Record<string, string | undefined>, envSchema: T) `
137145
138- Validates envvars against the schema and returns a typed configuration object
139- along with flags: ` isProduction ` , ` isTest ` , ` isDevelopment ` .
146+ Validates envvars against the schema and returns a typed configuration object.
147+
148+ ### ` detectNodeEnv `
149+
150+ ` detectNodeEnv(env: Record<string, string | undefined>) `
151+
152+ Standalone utility that reads NODE_ENV and returns an object with the following boolean flags:
153+
154+ - isProduction: true if NODE_ENV === 'production'
155+ - isTest: true if NODE_ENV === 'test'
156+ - isDevelopment: true if NODE_ENV === 'development'
140157
141158### ` EnvaseError `
142159
0 commit comments