Skip to main content

System

Runtime: Node.js; degrades in browsers — probes for process / window / navigator and falls back instead of throwing

Operating-system detection. In Node every helper reads process.platform and is the supported path.

Browser detection is deprecated

The navigator.userAgent branches — and isIOS, isAndroid and isTouchDevice, which only ever return true in a browser — are deprecated and go in the next major. Browser code belongs to @rtorcato/browser-common; the two packages do not overlap.

Example​

import { getPlatform, isMacOs } from '@rtorcato/js-common/system'

// Label a shortcut the way this platform writes it.
const shortcut = isMacOs() ? '⌘K' : 'Ctrl+K'

getPlatform() // 'macos' | 'windows' | 'linux' | ... from process.platform

Import​

import { getPlatform, isLinux, isMacOs } from '@rtorcato/js-common/system'

Exports​

NameSummary
getPlatformReturns a string representing the detected platform.
isAndroidDeprecated. Browser detection belongs to @rtorcato/browser-common; removed in the next major. Checks if the device is running Android.
isIOSDeprecated. Browser detection belongs to @rtorcato/browser-common; removed in the next major. Checks if the device is running iOS.
isLinuxChecks if the current OS is Linux.
isMacOsChecks if the current OS is macOS.
isTouchDeviceDeprecated. Browser detection belongs to @rtorcato/browser-common; removed in the next major. Checks if the device supports touch events.
isWindowsChecks if the current OS is Windows.

See also​

  • os — platform, arch, home and temp directories
  • node — Node version checks and optional requires
  • env — read env vars and branch on NODE_ENV
  • process — cwd, pid, uptime, exit, CI detection