Skip to content

Commit da2e0c7

Browse files
committed
use std-env in getEnvVar
1 parent ff157e5 commit da2e0c7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

packages/core/src/v3/utils/getEnv.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
export function getEnvVar(name: string, defaultValue?: string): string | undefined {
2-
// This could run in a non-Node.js environment (Bun, Deno, CF Worker, etc.), so don't just assume process.env is a thing
3-
if (typeof process !== "undefined" && typeof process.env === "object" && process.env !== null) {
4-
return process.env[name] ?? defaultValue;
5-
}
1+
import { env } from "std-env";
62

7-
return defaultValue;
3+
/**
4+
* Get an environment variable with optional default value. Runtime agnostic.
5+
*
6+
* @param name The name of the environment variable.
7+
* @param defaultValue The default value to return if the environment variable is not set.
8+
* @returns The value of the environment variable, or the default value if the environment variable is not set.
9+
*
10+
*/
11+
export function getEnvVar(name: string, defaultValue?: string): string | undefined {
12+
return env[name] ?? defaultValue;
813
}
914

1015
export function getNumberEnvVar(name: string, defaultValue?: number): number | undefined {

0 commit comments

Comments
 (0)