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 functions —
detectIsIOS(),detectIsMacOS(),detectIsAndroid(),detectIsWindows(),detectIsLinux(),detectIsChromeOS()— all synchronous and cached detectIsWindows11()— async; usesnavigator.userAgentData.getHighEntropyValues()in the browser andos.release()in Node.js- Device category —
isMobileDevice()andisDesktopDevice()for quick coarse checks - React hooks —
useOS()anduseIsWindows11()fromos-detect/react - Vue composables —
useOS()anduseIsWindows11()fromos-detect/vueas readonly refs - Node.js support — reads
process.platformwhennavigatoris absent;detectIsWindows11()usesos.release()build number - iPadOS 13+ detection — correctly identifies iPads that send
Macintoshin their userAgent vianavigator.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-detectReact hooks (optional peer dependency):
bash
npm install react@>=17Vue composables (optional peer dependency):
bash
npm install vue@>=3Quick 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 AndroidAll functions are synchronous and cached — safe to call on every render or in any reactive context.