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

v1.2.2

Published

Runtime-agnostic user-agent device detector

Readme

undevice

version downloads license coverage size

Unified Device Detector

Device, OS, and browser detection from User-Agent and CDN headers. Works in Node.js, browsers, and edge runtimes without framework dependencies.

  • ESM with TypeScript types.
  • Cloudflare and CloudFront header support.
  • Custom detection flags.
  • Dependency-free.
  • Adapters: Express, Fastify.

Documentation · Playground

Not affiliated with the UnJS organization.

Contents

Install

npm install undevice

Agent skill

Install the undevice skill to help your coding agent use the API, configure custom flags, and integrate detection into request handlers and SSR.

npx skills add teplostanski/undevice --skill undevice

For Express middleware and route types, use the Express skill.

npx skills add teplostanski/undevice --skill undevice-express

For Fastify plugins and route types, use the Fastify skill.

npx skills add teplostanski/undevice --skill undevice-fastify

Usage

Create a detector once, then pass each request's headers to detect():

import { undevice } from 'undevice'

const { detect } = undevice()
const device = detect({ headers: request.headers })

device.isMobile
device.isTablet
device.isDesktop

See the documentation for input options, flags, and API details.

Custom flags

import { undevice } from 'undevice'

const { detect } = undevice({ isRawClient: ['curl', 'wget'] })
const device = detect({ userAgent: 'curl/8.0' })

device.isRawClient // true

See Custom flags for callbacks, exclusions, and more examples.

Adapters

Express

import express from 'express'
import { undevice } from 'undevice/express'

const app = express()
app.use(undevice())

app.get('/device', (_req, res) => {
  res.json(res.locals.undevice)
})

See the Express guide for custom flags and TypeScript declarations.

Fastify

import Fastify from 'fastify'
import { undevice } from 'undevice/fastify'

const app = Fastify()
await app.register(undevice())

app.get('/device', async (request, reply) => {
  return reply.send(request.undevice)
})

See the Fastify guide for custom flags and TypeScript declarations.

CloudFront

When the User-Agent matches Amazon CloudFront case-insensitively, the following headers are checked:

  • CloudFront-Is-Android-Viewer
  • CloudFront-Is-Desktop-Viewer
  • CloudFront-Is-IOS-Viewer
  • CloudFront-Is-Mobile-Viewer
  • CloudFront-Is-Tablet-Viewer

Pass request headers via headers. If no device type header is true, the result includes isUnknown: true.

[!CAUTION] CloudFront does not provide headers for detecting Windows or macOS.

Configure device type headers in CloudFront.

Cloudflare

If the CloudFront rule does not apply and CF-Device-Type is mobile, tablet, or desktop, that value takes precedence over the User-Agent for device type detection. If the header is missing or its value is unrecognized, detection falls back to the User-Agent.

Configure Cache by device type in Cloudflare APO.

Compatibility

Node.js 22+. ESM only. Browsers and edge runtimes must support ES2022 APIs.

Credits

Inspired by @nuxtjs/device.

License

MIT License © 2026-PRESENT Teplostanski Igor