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

undevice

v0.1.3

Published

Runtime-agnostic user-agent device detector

Downloads

358

Readme

undevice

version downloads size license codecov

Runtime-agnostic device detection from User-Agent and CDN headers.

Works on Node.js, browsers, and edge runtimes.

Not affiliated with the UnJS organization.

Install

# npm
npm install undevice

# pnpm
pnpm install undevice

# yarn
yarn add undevice

# bun
bun install undevice

API

detectDevice

declare function detectDevice(input?: DetectDeviceInput): DeviceFlags

Pure function: does not read globals or mutate input. Default input is {}.

Types

type DeviceHeaders = Readonly<Record<string, string | undefined>>

type DetectDeviceInput = Readonly<{
  userAgent?: string
  headers?: DeviceHeaders
}>

// Boolean flags only (see Flags); does not include userAgent
type DeviceFlags = DeviceKindFlags & OsFlags & BrowserFlags & {
  isCrawler: boolean
}
  • DeviceHeaders keys are matched case-insensitively.
  • DeviceFlags does not echo the input userAgent.

Invariants

Exactly one device kind flag is true:

  • isMobile | isTablet | isDesktop | isUnknown

isMobileOrTablet and isDesktopOrTablet are derived from that kind.

Empty userAgent without a recognized CDN device hint yields isUnknown: true. Choosing a UI fallback is the caller's responsibility.

User-Agent matching is heuristic, not a security boundary.

Signal precedence

  1. CloudFront viewer headers — only when userAgent is Amazon CloudFront
  2. Cloudflare cf-device-type
  3. User-Agent string

Exports

| Kind | Name | | --------- | ------------------------------------------------------------------------------------------------------------------ | | Function | detectDevice | | Types | DetectDeviceInput, DeviceHeaders, DeviceFlags, DeviceKindFlags | | Constants | DeviceKind, BrowserName, CloudflareHeader, CloudflareDeviceType, CloudFrontHeader, CloudFrontUserAgent |

Usage

import { detectDevice } from "undevice";

const device = detectDevice({
  userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)",
});

device.isMobile; // true
device.isIos; // true
device.isSafari; // true
const device = detectDevice({
  userAgent: request.headers.get("user-agent") || undefined,
  headers: Object.fromEntries(request.headers),
});

For SSR, pass the same input on server and client.

Flags

Device kind:

  • isMobile
  • isTablet
  • isDesktop
  • isUnknown

Derived:

  • isMobileOrTablet
  • isDesktopOrTablet

OS:

  • isIos / isAndroid / isWindows / isMacOS / isLinux / isApple

Browser:

  • isChrome / isFirefox / isSafari / isEdge / isSamsung

Other:

  • isCrawler

CDN Headers

import { CloudflareHeader, CloudflareDeviceType, detectDevice } from "undevice";

detectDevice({
  userAgent: "Mozilla/5.0 ...",
  headers: {
    [CloudflareHeader.DeviceType]: CloudflareDeviceType.Mobile,
  },
});
import { CloudFrontHeader, CloudFrontUserAgent, detectDevice } from "undevice";

detectDevice({
  userAgent: CloudFrontUserAgent.AmazonCloudFront,
  headers: {
    [CloudFrontHeader.IsMobileViewer]: "true",
    [CloudFrontHeader.IsIosViewer]: "true",
  },
});

Constants

import {
  DeviceKind,
  BrowserName,
  CloudflareHeader,
  CloudflareDeviceType,
  CloudFrontHeader,
  CloudFrontUserAgent,
} from "undevice";

DeviceKind.Mobile; // "mobile"
CloudflareHeader.DeviceType; // "cf-device-type"

Feature set inspired by @nuxtjs/device.

License

MIT