UNPKG

codetrix

Version:

A lightweight lodash-style utility library

73 lines (72 loc) 2.53 kB
/** * Checks if code is running in a browser environment. * @returns {boolean} - True if running in a browser, false otherwise. */ export declare function isBrowser(): boolean; /** * Checks if code is running in a Node.js environment. * @returns {boolean} - True if running in Node.js, false otherwise. */ export declare function isNode(): boolean; /** * Checks if the browser is on a mobile device. * @returns {boolean} - True if mobile browser, false otherwise. */ export declare function isMobile(): boolean; /** * Check if the current device is Tablet. * Uses user-agent string. * @returns {boolean} - True if device is a tablet, otherwise false. */ export declare function isTablet(): boolean; /** * Check if the current device is Desktop. * Falls back when not detected as Mobile or Tablet. * @returns {boolean} - True if device is desktop, otherwise false. */ export declare function isDesktop(): boolean; /** * Checks if the environment is a serverless runtime (Vercel, AWS Lambda, etc.). * @returns {boolean} - True if serverless, false otherwise. */ export declare function isServerless(): boolean; /** * Checks if code is running inside a Web Worker. * @returns {boolean} - True if in Web Worker, false otherwise. */ export declare function isWebWorker(): boolean; /** * Checks if the environment is Electron (desktop apps). * @returns {boolean} - True if Electron, false otherwise. */ export declare function isElectron(): boolean; /** * Detects the runtime environment name. * @returns {"browser" | "node" | "deno" | "bun" | "electron" | "webworker" | "unknown"} */ export declare function getRuntimeEnv(): "browser" | "node" | "deno" | "bun" | "electron" | "webworker" | "unknown"; /** * Get the operating system name from the user agent. * @returns {string} OS name (e.g., "Windows", "macOS", "Linux", "Android", "iOS", "Unknown") */ export declare function getOS(): string; /** * Get the browser name from the user agent. * @returns {string} Browser name (e.g., "Chrome", "Safari", "Firefox", "Edge", "Opera", "Unknown") */ export declare function getBrowserName(): string; /** * getDeviceType * --------------------------------- * Detects the device type based on User-Agent. * Returns one of: "mobile" | "tablet" | "desktop". * * @returns {"mobile" | "tablet" | "desktop"} The detected device type. * * @example * ```ts * const type = getDeviceType(); * console.log(type); // "mobile" * ``` */ export declare function getDeviceType(): "mobile" | "tablet" | "desktop";