environment
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8889
91
95
0