Skip to content

API Reference

getOS

Returns a single string identifying the current operating system.

ts
import { getOS } from 'os-detect'

const os = getOS()
// 'ios' | 'macos' | 'android' | 'windows' | 'linux' | 'chromeos' | 'unknown'

Detection priority (first match wins):

  1. iOS / iPadOS
  2. Android
  3. ChromeOS
  4. Linux
  5. macOS
  6. Windows
  7. 'unknown'

ChromeOS is checked before Linux because ChromeOS userAgent strings contain "Linux" — checking in the wrong order would misidentify Chromebooks.

OS type

ts
type OS = 'ios' | 'macos' | 'android' | 'windows' | 'linux' | 'chromeos' | 'unknown'

Boolean detection

All functions are synchronous, side-effect-free, and cache their result after the first call.

ts
import {
  detectIsIOS,
  detectIsMacOS,
  detectIsAndroid,
  detectIsWindows,
  detectIsLinux,
  detectIsChromeOS,
} from 'os-detect'
FunctionReturns true whenNode.js behaviour
detectIsIOS()iPhone, iPod, or iPad (including iPadOS 13+)always false
detectIsMacOS()macOS desktop (correctly excludes iPadOS 13+)process.platform === 'darwin'
detectIsAndroid()Android phones and tabletsprocess.platform === 'android'
detectIsWindows()Windows desktop or laptop (32-bit and 64-bit)process.platform === 'win32'
detectIsLinux()Linux desktop (excludes Android and ChromeOS)process.platform === 'linux'
detectIsChromeOS()ChromeOS devicesalways false

iPadOS 13+ note

Since iPadOS 13, Safari reports Macintosh in the userAgent string. detectIsIOS() handles this correctly by checking navigator.maxTouchPoints > 1. detectIsMacOS() excludes iPadOS devices accordingly — you will never get true from both functions on the same device.

Example — conditional rendering

ts
import { detectIsIOS, detectIsAndroid, detectIsWindows } from 'os-detect'

if (detectIsIOS()) {
  // show App Store badge
} else if (detectIsAndroid()) {
  // show Google Play badge
} else if (detectIsWindows()) {
  // show Windows Store badge
}

detectIsWindows11

Asynchronous. Returns true only when both detectIsWindows() is true and the Windows 11 check succeeds.

ts
import { detectIsWindows11 } from 'os-detect'

const isWin11 = await detectIsWindows11() // Promise<boolean>

Browser — uses navigator.userAgentData.getHighEntropyValues(['platformVersion']) (Chrome 90+ / Edge 90+). Windows 11 reports platformVersion >= 13.0.0. Returns false if the API is unavailable or the call fails.

Node.js — uses os.release(). Windows 11 has build number >= 22000. Returns false if the import fails.

Returns false immediately if detectIsWindows() is false — no async work is done.

ts
// Differentiate Windows 10 from Windows 11
const isWindows = detectIsWindows()
const isWin11 = await detectIsWindows11()

if (isWin11) {
  console.log('Windows 11')
} else if (isWindows) {
  console.log('Windows 10 or older')
}

Device category

Quick coarse checks that group OS values into mobile and desktop buckets.

ts
import { isMobileDevice, isDesktopDevice } from 'os-detect'

isMobileDevice() // true if iOS or Android
isDesktopDevice() // true if macOS, Windows, Linux, or ChromeOS

Note: isMobileDevice() and isDesktopDevice() are not mutually exclusive. A device with an unrecognized OS returns false for both. There is no overlap on the currently recognised OS values.