System
Platform detection for client-side code — operating system, mobile platform, touch support. It reads navigator.userAgent, which is a heuristic and not a fact: browsers misreport, and iPadOS presents itself as macOS. Prefer feature detection where one exists, keep these for the cases where behaviour genuinely differs by platform (shortcut labels, store links), and use os or process on the server.
Example
import { isMacOs, isTouchDevice } from '@rtorcato/js-common/system'
// Label a shortcut the way this platform writes it.
const shortcut = isMacOs() ? '⌘K' : 'Ctrl+K'
if (isTouchDevice()) enableSwipeGestures()
Both read navigator, so they are heuristics: iPadOS reports itself as macOS, and a laptop with a
touchscreen answers yes to isTouchDevice. Feature-detect where you can.
Import
import { getPlatform, isAndroid, isIOS } from '@rtorcato/js-common/system'
Exports
| Name | Summary |
|---|---|
getPlatform | Returns a string representing the detected platform. |
isAndroid | Checks if the device is running Android. |
isIOS | Checks if the device is running iOS. |
isLinux | Checks if the current OS is Linux. |
isMacOs | Checks if the current OS is macOS. |
isTouchDevice | Checks if the device supports touch events. |
isWindows | Checks if the current OS is Windows. |