environment
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

environment

Check which JavaScript environment your code is running in at runtime

Install

npm install environment

Usage

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.

API

isBrowser

Check if the code is running in a web browser environment.

isNode

Check if the code is running in a Node.js environment.

isBun

Check if the code is running in a Bun environment.

isDeno

Check if the code is running in a Deno environment.

isElectron

Check if the code is running in an Electron environment.

isJsDom

Check if the code is running in a jsdom environment.

isWebWorker

Check if the code is running in a Web Worker environment, which could be either a dedicated worker, shared worker, or service worker.

isDedicatedWorker

Check if the code is running in a Dedicated Worker environment.

isSharedWorker

Check if the code is running in a Shared Worker environment.

isServiceWorker

Check if the code is running in a Service Worker environment.

Related

  • is - Type check values

Package Sidebar

Install

npm i environment

Weekly Downloads

334

Version

1.0.0

License

MIT

Unpacked Size

6.69 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus