npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@supercat1337/device-detect

v2.0.0

Published

A JavaScript library to detect browser, device, operating system, language, and time zone from the user agent string.

Readme

device-detect

A modern, SSR‑ready JavaScript library for detecting browser, device, OS, locale, and privacy features.

npm version License: MIT


Overview

device-detect gives you reliable information about your user’s environment using a combination of User‑Agent parsing, Client Hints, and modern browser APIs. It works in the browser and is safe for server‑side rendering (SSR).

Key capabilities:

  • Device: model name (e.g., "iPhone 14 Pro", "SM‑S911B"), type (mobile/tablet/desktop), touch/pointer support.
  • OS: name and version (Windows 11, macOS 14, Android 13, iOS 17…).
  • Browser: name, version, webview detection (Instagram, Facebook, Telegram, etc.).
  • Locale: time zone, list of preferred languages with human‑readable names.
  • Async & Sync APIs: most detection functions are asynchronous (use await) for accuracy, some are synchronous.

Live Demo

See it in action →


Installation

npm install @supercat1337/device-detect

Quick Start

The easiest way to get all information at once is getEnvironment():

import { getEnvironment } from '@supercat1337/device-detect';

async function showEnvironment() {
    const env = await getEnvironment();
    console.log(env);
    /*
    {
      browser: { name: "Chrome", version: "122.0.0.0" },
      os: { name: "Windows", version: "11" },
      device: { model: "Desktop", type: "desktop" },
      locale: {
        timeZone: "Europe/London",
        languages: ["English", "Russian (Russia)"]
      }
    }
    */
}

You can also use individual functions:

import {
    getBrowser,
    getOS,
    getDeviceModel,
    isMobile,
    getTimeZone,
    getLanguages,
} from '@supercat1337/device-detect';

async function example() {
    const browser = await getBrowser(); // "Chrome 122.0.0.0"
    const os = await getOS(); // "Windows 11"
    const model = await getDeviceModel(); // "SM-S911B" or "iPhone 14 Pro"
    const mobile = isMobile(); // true/false (synchronous)
    const tz = getTimeZone(); // "America/New_York"
    const langs = getLanguages(); // ["English", "French (France)"]
}

API Reference

Main function

getEnvironment(displayLocale?, customUserAgent?): Promise<EnvironmentInfo>

Returns a structured object with all detected information.

  • displayLocale – optional BCP47 tag (e.g. "ru") to localise language/country names.
  • customUserAgent – override User‑Agent string (useful for SSR).
interface EnvironmentInfo {
    browser: { name: string; version: string };
    os: { name: string; version: string };
    device: { model: string; type: 'desktop' | 'tablet' | 'mobile' };
    locale: { timeZone: string; languages: string[] };
}

Individual functions (asynchronous)

| Function | Returns | Description | | ---------------------------- | ------------------ | ------------------------------------------------------ | | getBrowser(userAgent?) | Promise<string> | Browser name + version (e.g., "Chrome 122") | | getOS(userAgent?) | Promise<string> | OS name + version (e.g., "Windows 11", "iOS 17.4") | | getDeviceModel(userAgent?) | Promise<string> | Specific device model or "Desktop" / "Unknown" | | isWebview(userAgent?) | Promise<boolean> | Running inside a webview (Instagram, Telegram, etc.) | | isWindows11() | Promise<boolean> | Windows 11 detection using Client Hints |

Synchronous functions

| Function | Returns | Description | | -------------------------------------------------- | ----------------------------------- | ---------------------------------------------------------------------- | | getDeviceType(userAgent?) | "desktop" \| "tablet" \| "mobile" | Device category | | isMobile(userAgent?) | boolean | Mobile phone (excluding tablets) | | isTablet(userAgent?) | boolean | Tablet detection | | isIPhone(userAgent?) | boolean | iPhone or iPod | | isIPad(userAgent?) | boolean | iPad (including modern iPads masking as Mac) | | isMac(userAgent?) | boolean | Apple desktop computer | | isPointerDevice() | boolean | Fine pointer (mouse/stylus) available | | isSensorDevice() | boolean | Touchscreen available | | getTimeZone() | string | IANA time zone (e.g., "Europe/Moscow") | | getLanguages(displayLocale?, fallbackLanguages?) | string[] | Human‑readable language list (e.g., ["English", "Russian (Russia)"]) | | getBrowserLanguage(localeName?) | string | Browser’s primary language name (e.g., "English") | | getAndroidDeviceName(userAgent?) | Promise<string> | Android marketing name (e.g., "SM-S911B") | | getAppleDeviceModel(userAgent?) | Promise<string> | Apple device model (e.g., "iPhone 15 Pro") |

Note: getCountryName is not included in getEnvironment – use it separately if needed.


SSR (Server‑Side Rendering)

All functions gracefully handle environments without window or navigator.
When used on the server, they return safe default values (e.g., "Unknown", false, "UTC").
For accurate results, pass a customUserAgent string (from your server request) to the relevant functions.

// Next.js / Nuxt example
const ua = req.headers['user-agent'];
const env = await getEnvironment(undefined, ua);

Browser Support

Works in all modern browsers (Chrome, Firefox, Safari, Edge, Opera).
Some advanced features require newer APIs:

  • Client Hints – Chromium‑based browsers, Safari (partial), Firefox (planned).
  • Intl.DisplayNames – required for human‑readable language names (polyfill available for very old browsers).

Legacy Internet Explorer is not supported.


License

MIT