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

@device-router/types

v0.4.0

Published

Core types, device classification, and rendering hint derivation for DeviceRouter

Readme

@device-router/types

Type definitions, device classification, and rendering hint derivation for DeviceRouter.

Installation

pnpm add @device-router/types

Usage

Classify device signals into tiers

import { classify } from '@device-router/types';

const tiers = classify({
  hardwareConcurrency: 8,
  deviceMemory: 8,
  connection: { effectiveType: '4g', downlink: 50 },
  gpuRenderer: 'ANGLE (Apple, Apple M2 Pro, OpenGL 4.1)',
});
// { cpu: 'high', memory: 'high', connection: 'fast', gpu: 'high' }

Derive rendering hints

import { classify, deriveHints } from '@device-router/types';

const tiers = classify(signals);
const hints = deriveHints(tiers, signals);
// {
//   deferHeavyComponents: false,
//   serveMinimalCSS: false,
//   reduceAnimations: false,
//   useImagePlaceholders: false,
//   disableAutoplay: false,
//   preferServerRendering: false,
//   disable3dEffects: false,
// }

Rendering hints are derived from tiers and transient signals:

| Hint | When true | | ----------------------- | ------------------------------------------------------ | | deferHeavyComponents | Low-end device, slow connection, or low battery | | serveMinimalCSS | Low-end device | | reduceAnimations | Low-end device, prefers reduced motion, or low battery | | useImagePlaceholders | Slow connection (2G/3G) | | disableAutoplay | Low-end device, slow connection, or low battery | | preferServerRendering | Low-end device | | disable3dEffects | No GPU or software renderer |

The battery signal bypasses tier classification — it's transient state, not a capability. When unplugged and below 15% charge, power-sensitive hints are forced on.

Custom thresholds

Override default tier boundaries:

import { classify } from '@device-router/types';

const tiers = classify(signals, {
  cpu: { lowUpperBound: 4, midUpperBound: 8 },
  memory: { midUpperBound: 8 },
  connection: { downlink4gUpperBound: 10 },
  gpu: { highEndPattern: /\bRTX\b|\bGTX\b/i },
});

Validate thresholds

Thresholds are validated automatically by createDeviceRouter(). For standalone usage with classify(), call validateThresholds() explicitly:

import { validateThresholds } from '@device-router/types';

validateThresholds({
  cpu: { lowUpperBound: 4, midUpperBound: 8 },
}); // OK

validateThresholds({
  cpu: { lowUpperBound: 10, midUpperBound: 2 },
}); // throws Error

Validate incoming signals

import { isValidSignals } from '@device-router/types';

if (isValidSignals(requestBody)) {
  // requestBody is typed as RawSignals
}

Tier classification

| Dimension | Low | Mid | High/Fast | | -------------- | ----------------- | ------------ | ----------------------------- | | CPU | 1-2 cores | 3-4 cores | 5+ cores | | Memory | <=2 GB | 2-4 GB | >4 GB | | Connection | 2G | 3G / slow 4G | Fast 4G+ (>=5 Mbps) | | GPU | Software renderer | Mid-range | RTX, RX 5000+, Apple M-series |

Exports

Functions

  • classify(signals, thresholds?) — Classify raw signals into DeviceTiers
  • classifyCpu(hardwareConcurrency?, thresholds?) — CPU tier
  • classifyMemory(deviceMemory?, thresholds?) — Memory tier
  • classifyConnection(effectiveType?, downlink?, thresholds?) — Connection tier
  • classifyGpu(renderer?, thresholds?) — GPU tier
  • deriveHints(tiers, signals?) — Derive RenderingHints from tiers and signals
  • validateThresholds(thresholds) — Validate custom thresholds (called automatically by middleware)
  • isValidSignals(body) — Type guard for RawSignals
  • isBotSignals(signals) — Detect bot/crawler/headless browser probe submissions
  • classifyFromHeaders(headers) — Classify from UA/Client Hints headers
  • resolveFallback(fallback) — Resolve a fallback profile preset or custom tiers

Constants

  • CONSERVATIVE_TIERS — Low-end device tier preset
  • OPTIMISTIC_TIERS — High-end device tier preset
  • ACCEPT_CH_VALUEAccept-CH header value for requesting Client Hints

Types

  • RawSignals — Browser-collected device signals
  • DeviceTiers — Classified capability tiers (cpu, memory, connection, gpu)
  • RenderingHints — Boolean rendering decisions
  • DeviceProfile — Full profile with schema version, session token, timestamps, and signals
  • ClassifiedProfile — Profile + tiers + hints + source
  • ProfileSource'probe' | 'headers' | 'fallback'
  • FallbackProfile'conservative' | 'optimistic' | DeviceTiers
  • TierThresholds — Custom threshold configuration
  • CpuTier, MemoryTier, ConnectionTier, GpuTier — Individual tier types

License

MIT