Skip to content

Commit

Permalink
refactor: improve environment variable handling with Zod transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
mherod committed Jan 3, 2025
1 parent be7055e commit 92946ae
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ config();

const EnvironmentSchema = z.object({
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
HOME: z.string().min(1),
HOME: z
.string()
.optional()
.transform((val) => val ?? process.env.USERPROFILE ?? "")
.pipe(z.string().min(1)),
});

/**
* Validated environment variables with type safety
* Validated environment variables with type safety and fallbacks
* @example
* // Using the environment variables
* if (env.LOG_LEVEL === "debug") {
Expand Down

0 comments on commit 92946ae

Please sign in to comment.