@oxog/env-scout
A comprehensive, lightweight, and zero-dependency environment detection library for JavaScript/TypeScript applications. Detect runtime environments, browsers, operating systems, devices, and features with ease.

Features
- Zero Dependencies - No external dependencies, keeping your bundle size minimal
- TypeScript Support - Full TypeScript support with comprehensive type definitions
- Tree-Shakeable - Import only what you need
- Cached Results - Automatic caching for performance optimization
- Comprehensive Detection - Detect runtime, browser, OS, device, network, and features
- Cross-Platform - Works in browsers, Node.js, Bun, Deno, and more
Installation
npm install @oxog/env-scout
yarn add @oxog/env-scout
pnpm add @oxog/env-scout
bun add @oxog/env-scout
Quick Start
import { isBrowser, getEnvironmentInfo, isEnvironment } from '@oxog/env-scout';
if (isBrowser() && isDarkMode()) {
}
if (isEnvironment(['browser', 'mobile', 'online'])) {
}
const env = getEnvironmentInfo();
console.log(env);
API Documentation
Runtime Environment Detection
isBrowser() | Running in web browser |
isNode() | Running in Node.js |
isBun() | Running in Bun runtime |
isDeno() | Running in Deno runtime |
isElectron() | Running in Electron |
isJsDom() | Running in jsdom |
isReactNative() | Running in React Native |
isCapacitor() | Running in Capacitor |
isCordova() | Running in Cordova |
isTauri() | Running in Tauri |
isWebWorker() | Any web worker |
isDedicatedWorker() | Dedicated worker |
isSharedWorker() | Shared worker |
isServiceWorker() | Service worker |
Browser Detection
isChrome() | Google Chrome browser |
isFirefox() | Mozilla Firefox browser |
isSafari() | Apple Safari browser |
isEdge() | Microsoft Edge browser |
isOpera() | Opera browser |
getBrowser() | Returns { name: string, version: string } |
isHeadlessBrowser() | Detect headless browsers |
Operating System Detection
isMacOs() | macOS operating system |
isWindows() | Windows operating system |
isLinux() | Linux operating system |
isIos() | iOS operating system |
isAndroid() | Android operating system |
getOS() | Returns OS name as string |
Device Detection
isMobile() | Mobile device |
isTablet() | Tablet device |
isDesktop() | Desktop device |
isTouchDevice() | Has touch support |
isRetina() | High DPI display |
getDeviceType() | Returns device type string |
Screen & Display
getScreenSize() | Returns { width: number, height: number } |
getOrientation() | Returns 'portrait' | 'landscape' |
isSmallScreen() | Screen width < 576px |
isMediumScreen() | Screen width 576px - 1200px |
isLargeScreen() | Screen width >= 1200px |
User Preferences
isDarkMode() | Prefers dark color scheme |
isLightMode() | Prefers light color scheme |
prefersReducedMotion() | Prefers reduced motion |
getColorScheme() | Returns 'dark' | 'light' | 'no-preference' |
getSystemLanguage() | Returns language code |
getTimezone() | Returns user timezone |
Network & Connection
isOnline() | Has network connection |
isOffline() | No network connection |
getConnectionType() | Returns connection type (wifi, cellular, etc.) |
isSlowConnection() | Slow network connection |
getConnectionInfo() | Complete connection details |
Feature Detection
isHTTPS() | Secure HTTPS connection |
hasWebGL() | WebGL support |
hasWebGL2() | WebGL2 support |
hasCanvas() | Canvas support |
hasWebAssembly() | WebAssembly support |
hasServiceWorkerSupport() | Service Worker support |
hasNotificationSupport() | Notification API support |
hasGeolocationSupport() | Geolocation API support |
Special Detection
isBot() | Search engine bot |
isPWA() | Progressive Web App |
isStandalone() | PWA standalone mode |
isIframe() | Running in iframe |
isLocalhost() | Local development |
isDevelopment() | Development environment |
isProduction() | Production environment |
Utility Functions
getEnvironmentInfo()
Returns complete environment information:
const info = getEnvironmentInfo();
isEnvironment(conditions: string[])
Check multiple conditions at once (AND logic):
isEnvironment(['browser', 'mobile', 'safari', 'ios']);
isEnvironment(['desktop', 'chrome', 'windows']);
isEnvironment(['pwa', 'online']);
checkFeatureSupport(features: string[])
Batch check multiple features:
const support = checkFeatureSupport(['webgl', 'canvas', 'webassembly']);
Usage Examples
Theme Detection and Application
import { isDarkMode, isLightMode, getColorScheme } from '@oxog/env-scout';
function applyTheme() {
if (isDarkMode()) {
document.body.classList.add('dark-theme');
} else if (isLightMode()) {
document.body.classList.add('light-theme');
} else {
document.body.classList.add('default-theme');
}
}
Responsive Feature Loading
import { isMobile, isSlowConnection, checkFeatureSupport } from '@oxog/env-scout';
async function loadFeatures() {
const features = checkFeatureSupport(['webgl', 'webassembly']);
if (isMobile() || isSlowConnection()) {
await import('./mobile-app');
} else if (features.webgl && features.webassembly) {
await import('./desktop-app');
} else {
await import('./basic-app');
}
}
Platform-Specific Code
import { isEnvironment, getOS } from '@oxog/env-scout';
function getPlatformSpecificPath() {
if (isEnvironment(['electron', 'windows'])) {
return 'C:\\Program Files\\MyApp';
} else if (isEnvironment(['electron', 'macos'])) {
return '/Applications/MyApp.app';
} else if (isEnvironment(['node', 'linux'])) {
return '/opt/myapp';
}
return './';
}
Analytics and Monitoring
import { getEnvironmentInfo, isBot } from '@oxog/env-scout';
function trackUser() {
if (isBot()) {
return;
}
const env = getEnvironmentInfo();
analytics.track('page_view', {
runtime: env.runtime,
browser: env.browser?.name,
os: env.os,
device: env.device.type,
screen_size: `${env.screen.width}x${env.screen.height}`,
connection: env.network.type
});
}
Browser Usage via CDN
You can also use env-scout directly in the browser:
<script src="https://unpkg.com/@oxog/env-scout/dist/index.js"></script>
<script>
const { isBrowser, getEnvironmentInfo } = window.EnvScout;
if (isBrowser()) {
console.log(getEnvironmentInfo());
}
</script>
Tree-Shaking
The library is designed to be tree-shakeable. When you import specific functions, only the code for those functions will be included in your bundle:
import { isMobile } from '@oxog/env-scout';
import { isMobile, isTablet, isDesktop } from '@oxog/env-scout/device';
Performance Considerations
- Detection results are cached automatically for 60 seconds to improve performance
- Functions use lazy evaluation where possible
- Feature detection is preferred over user agent parsing
- No external dependencies means faster load times
TypeScript Support
The library is written in TypeScript and provides comprehensive type definitions:
import type { EnvironmentInfo, BrowserInfo } from '@oxog/env-scout';
function processEnvironment(env: EnvironmentInfo) {
console.log(env.browser?.name);
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
)
- Commit your changes (
git commit -m 'Add some amazing feature'
)
- Push to the branch (
git push origin feature/amazing-feature
)
- Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Ersin Koç
Links