/** * Environment Detection Utilities * Centralized utilities for detecting runtime environment and accessing global objects safely * These utilities are used across the codebase to avoid ReferenceError and provide consistent environment detection */ import type { NavigatorWithConnection, EnvironmentInfo, ExtendedEnvironmentInfo } from '@plyaz/types/api'; export declare function getProcess(): globalThis.NodeJS.Process | null; /** * Safely get the window object if available * * @returns The window object if available, null otherwise * * @example * ```typescript * const win = getWindow(); * if (win) { * console.log(`Window width: ${win.innerWidth}`); * } * ``` */ export declare function getWindow(): Window | null; /** * Safely get the document object if available * * @returns The document object if available, null otherwise * * @example * ```typescript * const doc = getDocument(); * if (doc) { * const element = doc.getElementById('app'); * } * ``` */ export declare function getDocument(): Document | null; /** * Safely get the navigator object if available * * @returns The navigator object if available, null otherwise * * @example * ```typescript * const nav = getNavigator(); * if (nav) { * console.log(`User agent: ${nav.userAgent}`); * } * ``` */ export declare function getNavigator(): NavigatorWithConnection | null; /** * Check if navigator is available * Convenience function for boolean checks * * @returns True if navigator is available * * @example * ```typescript * if (hasNavigator()) { * // Navigator-specific code * } * ``` */ export declare function hasNavigator(): boolean; /** * Check if running in a browser environment * * @returns True if running in a browser, false otherwise * * @example * ```typescript * if (isBrowser()) { * // Browser-specific code * window.localStorage.setItem('key', 'value'); * } * ``` */ export declare function isBrowser(): boolean; /** * Check if running in a Node.js environment * * @returns True if running in Node.js, false otherwise * * @example * ```typescript * if (isNode()) { * // Node.js-specific code * const fs = require('fs'); * } * ``` */ export declare function isNode(): boolean; /** * Check if running in an Electron environment * * @returns True if running in Electron, false otherwise * * @example * ```typescript * if (isElectron()) { * // Electron-specific code * } * ``` */ export declare function isElectron(): boolean; /** * Check if running in a Web Worker environment * * @returns True if running in a Web Worker, false otherwise * * @example * ```typescript * if (isWebWorker()) { * // Web Worker-specific code * self.postMessage({ type: 'ready' }); * } * ``` */ export declare function isWebWorker(): boolean; /** * Check if running in a React Native environment * * @returns True if running in React Native, false otherwise * * @example * ```typescript * if (isReactNative()) { * // React Native-specific code * } * ``` */ export declare function isReactNative(): boolean; /** * Check if running in a Deno environment * * @returns True if running in Deno, false otherwise * * @example * ```typescript * if (isDeno()) { * // Deno-specific code * } * ``` */ export declare function isDeno(): boolean; /** * Check if running in a Bun environment * * @returns True if running in Bun, false otherwise * * @example * ```typescript * if (isBun()) { * // Bun-specific code * } * ``` */ export declare function isBun(): boolean; /** * Check if running in server-side rendering (SSR) context * * @returns True if running in SSR context, false otherwise * * @example * ```typescript * if (isSSR()) { * // SSR-specific code * // Avoid using browser APIs * } * ``` */ export declare function isSSR(): boolean; /** * Get the current runtime environment name * * @returns The name of the current runtime environment * * @example * ```typescript * const runtime = getRuntimeEnvironment(); * console.log(`Running in: ${runtime}`); * ``` */ export declare function getRuntimeEnvironment(): 'browser' | 'node' | 'electron' | 'deno' | 'bun' | 'webworker' | 'react-native' | 'unknown'; /** * Check if a global object exists * * @param name - The name of the global object to check * @returns True if the global object exists, false otherwise * * @example * ```typescript * if (hasGlobal('localStorage')) { * // localStorage is available * } * ``` */ export declare function hasGlobal(name: string): boolean; /** * Get a global object safely * * @param name - The name of the global object to get * @returns The global object if available, undefined otherwise * * @example * ```typescript * const storage = getGlobal('localStorage'); * if (storage) { * storage.setItem('key', 'value'); * } * ``` */ export declare function getGlobal(name: string): T | undefined; /** * Get comprehensive environment information * * @returns Detailed environment information * * @example * ```typescript * const env = getEnvironmentInfo(); * console.log(`Runtime: ${env.runtime}`); * console.log(`Is Browser: ${env.isBrowser}`); * ``` */ export declare function getEnvironmentInfo(): EnvironmentInfo; /** * Get environment variable safely * * @param name - Environment variable name * @param defaultValue - Default value if not found * @returns Environment variable value or default * * @example * ```typescript * const apiUrl = getEnv('API_URL', 'http://localhost:3000'); * ``` */ export declare function getEnv(name: string, defaultValue?: string): string | undefined; export declare function isDevelopment(): boolean; /** * Check if running in production environment * * @returns True if in production mode * * @example * ```typescript * if (isProduction()) { * enableAnalytics(); * } * ``` */ export declare function isProduction(): boolean; /** * Check if running in test environment * * @returns True if in test mode * * @example * ```typescript * if (isTest()) { * mockApiCalls(); * } * ``` */ export declare function isTest(): boolean; export declare function isStaging(): boolean; /** * Get the current environment name * * @returns Environment name * * @example * ```typescript * const env = getEnvironmentName(); * console.log(`Running in ${env} mode`); * ``` */ export declare function getEnvironmentName(): 'development' | 'production' | 'test' | 'staging' | 'unknown'; /** * Check if debug mode is enabled * * @returns True if debug mode is enabled * * @example * ```typescript * if (isDebug()) { * console.log('Debug info:', data); * } * ``` */ export declare function isDebug(): boolean; /** * Check if running in CI/CD environment * * @returns True if in CI/CD * * @example * ```typescript * if (isCI()) { * runIntegrationTests(); * } * ``` */ export declare function isCI(): boolean; /** * Check if document is visible (not hidden) * * @returns True if document is visible * * @example * ```typescript * if (!isDocumentVisible()) { * pauseAnimations(); * } * ``` */ export declare function isDocumentVisible(): boolean; /** * Check if page has focus * * @returns True if page has focus * * @example * ```typescript * if (isPageFocused()) { * startPolling(); * } * ``` */ export declare function isPageFocused(): boolean; /** * Check if running in iframe * * @returns True if in iframe * * @example * ```typescript * if (isInIframe()) { * adjustLayout(); * } * ``` */ export declare function isInIframe(): boolean; /** * Check if localStorage is available * * @returns True if localStorage is available * * @example * ```typescript * if (hasLocalStorage()) { * localStorage.setItem('key', 'value'); * } * ``` */ export declare function hasLocalStorage(): boolean; /** * Check if sessionStorage is available * * @returns True if sessionStorage is available * * @example * ```typescript * if (hasSessionStorage()) { * sessionStorage.setItem('temp', 'data'); * } * ``` */ export declare function hasSessionStorage(): boolean; /** * Get localStorage safely * * @returns localStorage if available, null otherwise * * @example * ```typescript * const storage = getLocalStorage(); * if (storage) { * storage.setItem('key', 'value'); * } * ``` */ export declare function getLocalStorage(): Storage | null; /** * Get sessionStorage safely * * @returns sessionStorage if available, null otherwise * * @example * ```typescript * const storage = getSessionStorage(); * if (storage) { * storage.setItem('key', 'value'); * } * ``` */ export declare function getSessionStorage(): Storage | null; /** * Check if IndexedDB is available * * @returns True if IndexedDB is available * * @example * ```typescript * if (hasIndexedDB()) { * openDatabase(); * } * ``` */ export declare function hasIndexedDB(): boolean; export declare function getCrypto(): Crypto | null; /** * Generate a UUID v4 * Cross-platform UUID generation using available crypto APIs * * @returns UUID string or fallback pseudo-random ID * * @example * ```typescript * const id = generateUUID(); * // '550e8400-e29b-41d4-a716-446655440000' * ``` */ export declare function generateUUID(): string; /** * Check if WebGL is supported * * @returns True if WebGL is supported * * @example * ```typescript * if (hasWebGL()) { * init3DGraphics(); * } * ``` */ export declare function hasWebGL(): boolean; /** * Check if WebP image format is supported * * @returns Promise resolving to true if WebP is supported * * @example * ```typescript * const supportsWebP = await hasWebPSupport(); * if (supportsWebP) { * useWebPImages(); * } * ``` */ export declare function hasWebPSupport(): Promise; /** * Check if running in server environment (Node.js) * Alias for isNode() but with semantic meaning for server-side code */ export declare function isServer(): boolean; /** * Get user agent safely */ export declare function getUserAgent(): string; /** * Check if device supports touch */ export declare function isTouchDevice(): boolean; /** * Check if device is mobile (basic check) */ export declare function isMobile(): boolean; /** * Check if browser supports localStorage * Alias for hasLocalStorage() with semantic name */ export declare function supportsLocalStorage(): boolean; /** * Check if browser supports sessionStorage * Alias for hasSessionStorage() with semantic name */ export declare function supportsSessionStorage(): boolean; /** * Check if browser supports WebSocket */ export declare function supportsWebSocket(): boolean; /** * Check if browser supports Service Workers */ export declare function supportsServiceWorker(): boolean; /** * Check if browser supports Push API */ export declare function supportsPushNotifications(): boolean; /** * Check if browser supports Notification API */ export declare function supportsNotifications(): boolean; /** * Check if browser supports fetch API */ export declare function supportsFetch(): boolean; /** * Check if browser supports IntersectionObserver */ export declare function supportsIntersectionObserver(): boolean; /** * Check if browser supports requestIdleCallback */ export declare function supportsRequestIdleCallback(): boolean; /** * Check if browser supports BroadcastChannel */ export declare function supportsBroadcastChannel(): boolean; /** * Check if browser supports Geolocation API */ export declare function supportsGeolocation(): boolean; /** * Get location object safely */ export declare function getLocation(): Location | null; /** * Get console object safely (works in both browser and Node) */ export declare function getConsole(): Console; /** * Execute code only in browser environment */ export declare function inBrowser(callback: () => T, fallback?: T): T | undefined; /** * Execute code only in server environment */ export declare function inServer(callback: () => T, fallback?: T): T | undefined; /** * Get extended environment info object */ export declare function getExtendedEnvironmentInfo(): ExtendedEnvironmentInfo; /** * Export all utilities as a namespace for convenience */ export declare const Environment: { readonly getProcess: typeof getProcess; readonly getWindow: typeof getWindow; readonly getDocument: typeof getDocument; readonly getNavigator: typeof getNavigator; readonly hasNavigator: typeof hasNavigator; readonly isBrowser: typeof isBrowser; readonly isNode: typeof isNode; readonly isElectron: typeof isElectron; readonly isWebWorker: typeof isWebWorker; readonly isReactNative: typeof isReactNative; readonly isDeno: typeof isDeno; readonly isBun: typeof isBun; readonly isSSR: typeof isSSR; readonly getRuntimeEnvironment: typeof getRuntimeEnvironment; readonly hasGlobal: typeof hasGlobal; readonly getGlobal: typeof getGlobal; readonly getEnvironmentInfo: typeof getEnvironmentInfo; readonly getEnv: typeof getEnv; readonly isDevelopment: typeof isDevelopment; readonly isProduction: typeof isProduction; readonly isTest: typeof isTest; readonly isStaging: typeof isStaging; readonly getEnvironmentName: typeof getEnvironmentName; readonly isDebug: typeof isDebug; readonly isCI: typeof isCI; readonly isDocumentVisible: typeof isDocumentVisible; readonly isPageFocused: typeof isPageFocused; readonly isInIframe: typeof isInIframe; readonly hasLocalStorage: typeof hasLocalStorage; readonly hasSessionStorage: typeof hasSessionStorage; readonly hasIndexedDB: typeof hasIndexedDB; readonly hasWebGL: typeof hasWebGL; readonly getCrypto: typeof getCrypto; readonly generateUUID: typeof generateUUID; readonly hasWebPSupport: typeof hasWebPSupport; readonly isServer: typeof isServer; readonly getUserAgent: typeof getUserAgent; readonly isTouchDevice: typeof isTouchDevice; readonly isMobile: typeof isMobile; readonly supportsLocalStorage: typeof supportsLocalStorage; readonly supportsSessionStorage: typeof supportsSessionStorage; readonly supportsWebSocket: typeof supportsWebSocket; readonly supportsServiceWorker: typeof supportsServiceWorker; readonly supportsPushNotifications: typeof supportsPushNotifications; readonly supportsNotifications: typeof supportsNotifications; readonly supportsFetch: typeof supportsFetch; readonly supportsIntersectionObserver: typeof supportsIntersectionObserver; readonly supportsRequestIdleCallback: typeof supportsRequestIdleCallback; readonly supportsBroadcastChannel: typeof supportsBroadcastChannel; readonly supportsGeolocation: typeof supportsGeolocation; readonly getLocation: typeof getLocation; readonly getConsole: typeof getConsole; readonly inBrowser: typeof inBrowser; readonly inServer: typeof inServer; readonly getExtendedEnvironmentInfo: typeof getExtendedEnvironmentInfo; }; //# sourceMappingURL=environment.d.ts.map