detecctio
v1.0.0
Published
Lightweight detection library for OS, browser, and device type across every JS environment
Downloads
149
Maintainers
Readme
DeteccioJS
Lightweight, zero-dependency detection library for OS, browser, and device type.
Works in every JS environment — React, Vue, Angular, vanilla, SSR (Node-safe).
Install
npm install detecctioNamed exports (tree-shakeable)
import { isIOS, isMobile, isTouchDevice, isSafari } from "detecctio";
if (isIOS) { /* ... */ }
if (isTouchDevice) { /* ... */ }Full list
| Export | Description |
|---|---|
| isIOS | iPhone, iPad, iPod (incl. iPadOS 13+) |
| isAndroid | Android |
| isWindows | Windows |
| isMacOS | macOS (excludes iOS) |
| isLinux | Linux (excludes Android) |
| isSafari | Safari (excludes Chromium-based) |
| isChrome | Chrome / Chromium / CriOS |
| isFirefox | Firefox / FxiOS |
| isOpera | Opera |
| isEdge | Edge (Chromium & legacy) |
| isIE | Any Internet Explorer |
| isIE9 | Internet Explorer 9 specifically |
| isIPhone | iPhone |
| isIPad | iPad (incl. iPadOS 13+) |
| isMobile | Mobile phones (not tablets) |
| isTablet | Tablets |
| isDesktop | Not mobile and not tablet |
| isTouchDevice | Has touch capability |
Class-based API
import { DetecctioJS } from "detecctio";
new DetecctioJS({
windowObject: true, // creates window.detecctio object with all booleans
documentClasses: "html", // adds classes to <html> e.g. "is-ios", "is-touch-device"
// also accepts: "body" | any CSS selector | false
});window.detecctio
When windowObject: true is set, window.detecctio is populated with all boolean flags:
console.log(window.detecctio.isDesktop); // true | falseCSS classes
When documentClasses targets an element, active detections are added as kebab-case classes:
<html class="is-desktop is-chrome is-windows">CDN / UMD
<script src="https://unpkg.com/detecctio/dist/index.umd.js"></script>
<script>
const { isIOS, DetecctioJS } = DetecctioJS;
</script>SSR / Node
All detections are SSR-safe — no crash when window or navigator is absent; values default to false.
Development
nvm use # uses .nvmrc (Node 20)
npm install
npm run build # ESM + CJS + UMD
npm test # Vitest
npm run typecheck