Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

environment

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

environment - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

25

index.d.ts

@@ -50,1 +50,26 @@ /**

export const isServiceWorker: boolean;
/**
Check if the code is running on macOS.
*/
export const isMacOs: boolean;
/**
Check if the code is running on Windows.
*/
export const isWindows: boolean;
/**
Check if the code is running on Linux.
*/
export const isLinux: boolean;
/**
Check if the code is running on iOS.
*/
export const isIos: boolean;
/**
Check if the code is running on Android.
*/
export const isAndroid: boolean;

27

index.js

@@ -1,2 +0,1 @@

/* eslint-disable n/prefer-global/process */
/* globals WorkerGlobalScope, DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, ServiceWorkerGlobalScope */

@@ -23,1 +22,27 @@

export const isServiceWorker = typeof ServiceWorkerGlobalScope !== 'undefined' && globalThis instanceof ServiceWorkerGlobalScope;
// Note: I'm intentionally not DRYing up the other variables to keep them "lazy".
const platform = globalThis.navigator?.userAgentData?.platform;
export const isMacOs = platform === 'macOS'
|| globalThis.navigator?.platform === 'MacIntel' // Even on Apple silicon Macs.
|| globalThis.navigator?.userAgent?.includes(' Mac ') === true
|| globalThis.process?.platform === 'darwin';
export const isWindows = platform === 'Windows'
|| globalThis.navigator?.platform === 'Win32'
|| globalThis.process?.platform === 'win32';
export const isLinux = platform === 'Linux'
|| globalThis.navigator?.platform?.startsWith('Linux') === true
|| globalThis.navigator?.userAgent?.includes(' Linux ') === true
|| globalThis.process?.platform === 'linux';
export const isIos = platform === 'iOS'
|| (globalThis.navigator?.platform === 'MacIntel' && globalThis.navigator?.maxTouchPoints > 1)
|| /iPad|iPhone|iPod/.test(globalThis.navigator?.platform);
export const isAndroid = platform === 'Android'
|| globalThis.navigator?.platform === 'Android'
|| globalThis.navigator?.userAgent?.includes(' Android ') === true
|| globalThis.process?.platform === 'android';
{
"name": "environment",
"version": "1.0.0",
"version": "1.1.0",
"description": "Check which JavaScript environment your code is running in at runtime: browser, Node.js, Bun, etc",

@@ -52,9 +52,24 @@ "license": "MIT",

"worker",
"serviceworker"
"serviceworker",
"macos",
"ios",
"iphone",
"ipad",
"windows",
"linux",
"android",
"os",
"operating",
"system"
],
"devDependencies": {
"ava": "^6.1.2",
"ava": "^6.1.3",
"typescript": "^5.4.5",
"xo": "^0.58.0"
},
"xo": {
"rules": {
"n/prefer-global/process": "off"
}
}
}

@@ -70,4 +70,26 @@ # environment

### `isMacOs`
Check if the code is running on macOS.
### `isWindows`
Check if the code is running on Windows.
### `isLinux`
Check if the code is running on Linux.
### `isIos`
Check if the code is running on iOS.
### `isAndroid`
Check if the code is running on Android.
## Related
- [is-in-ci](https://github.com/sindresorhus/is-in-ci) - Check if the process is running in a CI environment
- [is64bit](https://github.com/sindresorhus/is64bit) - Check if the operating system CPU architecture is 64-bit or 32-bit
- [is](https://github.com/sindresorhus/is) - Type check values
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc