The `is-browser` package is a minimalist utility designed to determine if the current JavaScript execution environment is a web browser. It exports a single boolean value: `true` if executed in a browser context (detecting `window` and `document` globals), and `false` otherwise (typically in a Node.js environment). The package is at version `2.1.0` and has not received updates since 2018, indicating a mature, stable, but currently unmaintained codebase. Its primary use case is for simple conditional logic in universal JavaScript libraries that need to adapt behavior based on the runtime environment. Unlike more modern alternatives like `browser-or-node` (which offers checks for Web Workers, JSDOM, or Deno), `is-browser` provides only a basic browser vs. non-browser distinction. It has no external runtime dependencies, ensuring a minimal footprint.
npm install is-browserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `is-browser` to conditionally execute code based on the runtime environment (browser vs. Node.js).
For more robust and up-to-date environment detection, consider alternatives like `browser-or-node` (version 3.0.0, last updated 2 years ago) which explicitly checks for Web Workers, Deno, and JSDOM.
Evaluate if the project's long-term stability requires a more actively maintained environment detection library. If strict evergreen compatibility is needed, migrating to a different package is advisable.
When using ESM, use `import isBrowser from 'is-browser';` instead of `require`. Ensure your project is configured for ESM or transpiles CommonJS modules correctly.
The `is-browser` package exports a boolean directly. Use it as a variable: `if (isBrowser) { /* ... */ }` or `console.log(isBrowser);`.No dependency data recorded yet.