GuardsMiscellaneous Guards
Environment Guards
Runtime type guards to check different environments.
Runtime type guards to check different environments.
isBrowser
Determines if code is running in a web browser environment
Signature
isBrowser(): booleanDescription
Determines if code is running in a web browser environment by checking for:
windowobjectdocumentobject
Examples
playground.ts
// Environment-specific logic
function getWindowSize() {
if (isBrowser()) {
return {
width: window.innerWidth,
height: window.innerHeight
};
}
return null;
}isNode
Determines if code is running in a Node.js environment
Signature
isNode(): booleanDescription
Determines if code is running in a Node.js environment by checking:
- process object
- process.versions.node
- Absence of browser APIs
Examples
playground.ts
// Module loading
function loadModule() {
if (isNode()) {
return require('fs'); // Node-specific module
}
throw new Error('Node.js required');
}isEnvironment
Checks if the current Node.js environment matches the specified value (case-sensitive).
Signature
isEnvironment(env: string): booleanDescription
Common values:
- "development"
- "production"
- "test"
Examples
playground.ts
// Environment-specific config
function getConfig() {
return isEnvironment('production')
? productionConfig
: developmentConfig;
}Aliases
| Main Export | Alias Names |
|---|---|
isEnvironment | isExpectedNodeENV, isNodeENV, isNodeEnvironment |
Last updated: Sun, Jun 07, 2026 05:56:18PM (UTC)
