-
-
Notifications
You must be signed in to change notification settings - Fork 0
5.2 environment variables
wiki[bot] edited this page Aug 23, 2026
·
1 revision
Utilities for parsing environment variables as boolean or numeric values.
Parses an environment variable value into a boolean.
import { getBooleanEnv } from "@triplef/helpers/get-boolean-env";function getBooleanEnv(
value?: string | null,
fallback?: boolean
): boolean | null;| Parameter | Type | Description |
|---|---|---|
value |
string | null | undefined |
The environment variable value to parse |
fallback |
boolean (optional) |
Fallback value if input is undefined/null |
-
trueif the value starts with"true"(case-insensitive) -
falseif the value starts with anything else -
fallbackif provided and value is undefined/null -
nullif no fallback provided and value is undefined/null
getBooleanEnv("true"); // true
getBooleanEnv("TRUE"); // true
getBooleanEnv("false"); // false
getBooleanEnv("0"); // false
getBooleanEnv("anything"); // false
getBooleanEnv(undefined, false); // false
getBooleanEnv(null, true); // true
getBooleanEnv(undefined); // nullParses an environment variable string into bytes. Supports units: B, KB, MB, GB, TB.
import { getByteSizeEnv } from "@triplef/helpers/get-byte-size-env";function getByteSizeEnv(
value?: string | null,
fallback?: number
): number | null;| Parameter | Type | Description |
|---|---|---|
value |
string | null | undefined |
The environment variable value to parse |
fallback |
number (optional) |
Fallback value if parsing fails |
getByteSizeEnv("100B"); // 100
getByteSizeEnv("1KB"); // 1024
getByteSizeEnv("1MB"); // 1048576
getByteSizeEnv("1.5GB"); // 1610612736
getByteSizeEnv("1tb"); // 1099511627776
getByteSizeEnv(null, 1024); // 1024
getByteSizeEnv("invalid", 0); // 0
getByteSizeEnv(undefined); // nullParses an environment variable string into a number, supporting both integers and floats. Automatically normalizes commas to periods for European decimal notation.
import { getNumberEnv } from "@triplef/helpers/get-number-env";function getNumberEnv(
value?: string | null,
fallback?: number
): number | bigint | null;| Parameter | Type | Description |
|---|---|---|
value |
string | null | undefined |
The environment variable value to parse |
fallback |
number (optional) |
Fallback value if parsing fails |
- Parses the provided string
- Falls back to
fallbackif value is null, undefined, or invalid - Returns
nullif parsing fails and no fallback provided
getNumberEnv("42"); // 42
getNumberEnv("3.14"); // 3.14
getNumberEnv("1,5"); // 1.5 (comma normalized)
getNumberEnv(null, 10); // 10
getNumberEnv("invalid", 0); // 0
getNumberEnv(undefined); // null
getNumberEnv(""); // null