Skip to content

os-detect

Lightweight OS and device-type detection for browsers, Node.js, and SSR — with React hooks and Vue composables. No dependencies.

Features

  • getOS() — returns a typed string identifier for the current OS; detection priority ensures ChromeOS is never misidentified as Linux
  • Boolean functionsdetectIsIOS(), detectIsMacOS(), detectIsAndroid(), detectIsWindows(), detectIsLinux(), detectIsChromeOS() — all synchronous and cached
  • detectIsWindows11() — async; uses navigator.userAgentData.getHighEntropyValues() in the browser and os.release() in Node.js
  • Device categoryisMobileDevice() and isDesktopDevice() for quick coarse checks
  • React hooksuseOS() and useIsWindows11() from os-detect/react
  • Vue composablesuseOS() and useIsWindows11() from os-detect/vue as readonly refs
  • Node.js support — reads process.platform when navigator is absent; detectIsWindows11() uses os.release() build number
  • iPadOS 13+ detection — correctly identifies iPads that send Macintosh in their userAgent via navigator.maxTouchPoints
  • Result cache — every function caches its result after the first call; zero overhead on subsequent calls
  • Zero runtime dependencies — no external packages; React and Vue are optional peer deps
  • Tree-shakeable ESM — import only what you use; UMD and CJS bundles also included

Installation

bash
npm install os-detect

React hooks (optional peer dependency):

bash
npm install react@>=17

Vue composables (optional peer dependency):

bash
npm install vue@>=3

Quick start

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

console.log(getOS()) // 'windows' | 'macos' | 'ios' | 'android' | 'linux' | 'chromeos' | 'unknown'
console.log(detectIsIOS()) // true on iPhone / iPad
console.log(detectIsWindows()) // true on Windows desktop
console.log(isMobileDevice()) // true on iOS or Android

All functions are synchronous and cached — safe to call on every render or in any reactive context.