|
|
5 months ago | |
|---|---|---|
| .. | ||
| index.d.ts | 5 months ago | |
| index.js | 5 months ago | |
| license | 5 months ago | |
| package.json | 5 months ago | |
| readme.md | 5 months ago | |
Check which JavaScript environment your code is running in at runtime
npm install environment
import {isBrowser, isNode} from 'environment';
if (isBrowser) {
console.log('Running in a browser!');
}
if (isNode) {
console.log('Running in Node.js!');
}
[!NOTE] Runtime checks should be used sparingly. Prefer conditional package exports and imports whenever possible.
isBrowserCheck if the code is running in a web browser environment.
isNodeCheck if the code is running in a Node.js environment.
isBunCheck if the code is running in a Bun environment.
isDenoCheck if the code is running in a Deno environment.
isElectronCheck if the code is running in an Electron environment.
isJsDomCheck if the code is running in a jsdom environment.
isWebWorkerCheck if the code is running in a Web Worker environment, which could be either a dedicated worker, shared worker, or service worker.
isDedicatedWorkerCheck if the code is running in a Dedicated Worker environment.
isSharedWorkerCheck if the code is running in a Shared Worker environment.
isServiceWorkerCheck if the code is running in a Service Worker environment.
isMacOsCheck if the code is running on macOS.
isWindowsCheck if the code is running on Windows.
isLinuxCheck if the code is running on Linux.
isIosCheck if the code is running on iOS.
isAndroidCheck if the code is running on Android.