Env
The env
module provides utility functions to detect and interact with the code execution environment, including:
- Detection of operating system and runtime (Node.js, Deno, Bun, browser)
- Environment checking (development/production)
- Manipulation of environment variables
- Detection of context type (server, browser, workers)
- Mobile device identification
All functions are optimized to work in different environments and return consistent results regardless of platform.
Overview
equalsEnv(env: string): boolean;
Checks if the current environment matches the given value (env
).
getEnv(key: string): string | undefined;
Gets the value of an environment variable.
getOS(): 'windows' | 'macos' | 'linux' | 'android' | 'ios' | 'unknown';
Detects the current operating system.
getRuntime(): 'node' | 'deno' | 'bun' | 'browser' | 'unknown';
Detects the execution runtime.
hasEnv(key: string): boolean;
Checks if an environment variable is set.
isBrowser(): boolean;
Checks if the code is running in a browser.
isBun(): boolean;
Checks if the code is running in the Bun environment.
isDedicatedWorker(): boolean;
Checks if the code is running in a Dedicated Worker.
isDeno(): boolean;
Checks if the code is running in the Deno environment.
isDev(): boolean;
Checks if the environment is in development mode.
isMobile(): boolean;
Checks if the code is running on a mobile device.
isNode(): boolean;
Checks if the code is running in Node.js.
isProd(): boolean;
Checks if the environment is in production mode.
isServer(): boolean;
Checks if the code is running in a server environment (not browser).
isServiceWorker(): boolean;
Checks if the code is running in a Service Worker.
isWebWorker(): boolean;
Checks if the code is running in any type of Web Worker.