New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@utilify/environment

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@utilify/environment

A utility library for detecting the runtime environment (Node.js, browser, Deno, etc.) and various environment-specific properties.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
0
Created
Source

Environment Utilities

The Environment category contains utility functions that help detect and identify the environment in which the code is running, whether it's in the browser, server, or within different types of workers. These functions are useful for providing environment-specific behaviors.

Installation

To install the environment utilities, use one of the following commands, depending on your package manager:

npm install @utilify/environment
yarn add @utilify/environment
pnpm add @utilify/environment

Once installed, you can import the functions into your project, using either ESM or CJS.

Usage

This library supports both ESM and CJS module systems.

import { isBrowser } from '@utilify/environment'; 
const { isBrowser } = require('@utilify/environment');  

Overview

Here’s an overview of the functions available in the environment category:

getOS

function getOS(): string | undefined;

Returns the user's operating system based on the browser's userAgent. Returns undefined if executed in the server.

isBun

function isBun(): boolean;

Checks if the code is running in the Bun environment by identifying the execution type through the Bun object.

isBrowser

function isBrowser(): boolean;

Checks if the code is running in a browser environment by checking the type of window.

isDeno

function isDeno(): boolean;

Checks if the code is running in the Deno environment by verifying the presence of the Deno object.

isDedicatedWorker

function isDedicatedWorker(): boolean;

Determines if the code is running inside a Dedicated Worker by checking the type of self.

isMobile

function isMobile(): boolean | undefined;

Checks if the code is running on a mobile device based on the browser's userAgent.

isNode

function isNode(): boolean;

Determines if the code is running in a Node.js environment by checking the presence of global and process objects.

isServer

function isServer(): boolean;

Detects if the code is running on the server by checking if the environment is Node.js, Deno, or Bun.

isServiceWorker

function isServiceWorker(): boolean;

Checks if the code is running inside a Service Worker by using the type of self.

isSharedWorker

function isSharedWorker(): boolean;

Determines if the code is running inside a Shared Worker by checking the type of self.

isWebWorker

function isWebWorker(): boolean;

Checks if the code is running inside any type of Web Worker, including Dedicated, Shared, or Service Worker.

Keywords

environment

FAQs

Package last updated on 12 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts