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 🙏

© 2025 – Pkg Stats / Ryan Hefner

device-type-detection

v1.0.1

Published

A Node Module to detect device type and orientation with SSR-safe guards and throttled resize listeners.

Readme

device-type-detection

A tiny React hook in form of node module to detect device type and orientation in browsers. It supports mobile, tablet, desktop, TV, and 4K screens, exposing granular breakpoints and orientation flags.

npm version

Features

  • Detects mobile (small/medium/large), tablet (small/medium/large), laptop, desktop, TV, and 4K TV
  • Provides portrait vs. landscape orientation
  • Touch detection via navigator.maxTouchPoints and react-device-detect
  • Throttled resize listener for performance
  • Full TypeScript support with declaration files

Peer Dependencies

This package relies on the following peer dependencies. Make sure they are installed in your project:

npm install react react-dom lodash react-device-detect
yarn add react react-dom lodash react-device-detect

Installation

npm install device-type-detection
yarn add device-type-detection

Quick Start

import React from "react";

import { useDeviceTypeDetection } from "device-type-detection";

const App: React.FC = () => {
  const {
    deviceType,
    orientation,
    isMobile,
    isTablet,
    isDesktop,
    isTV,
    isPortrait,
    isLandscape,
    // ...many more flags
  } = useDeviceTypeDetection();

  return (
    <div>
      <p>
        Device: <strong>{deviceType}</strong>
      </p>
      <p>
        Orientation: <strong>{orientation}</strong>
      </p>
      {isMobile && <p>This is a mobile device.</p>}
    </div>
  );
};

export default App;

API

useDeviceTypeDetection()

Returns a DeviceDetectionResult object with the following properties:

| Property | Type | Description | | -------------------- | --------------------------- | ------------------------------------------------------------------------------ | | deviceType | string | One of the DEVICE_TYPE enum values with _VERTICAL or _HORIZONTAL suffix. | | touchDevice | boolean | True if the device supports touch (maxTouchPoints > 0). | | isPortrait | boolean | True if viewport height > width. | | isLandscape | boolean | True if viewport width > height. | | orientation | 'portrait' \| 'landscape' | Shorthand for portrait vs. landscape. | | isMobile | boolean | Device is any mobile (MOBILE_S, MOBILE_M, MOBILE_L). | | isTablet | boolean | Device is any tablet (TABLET_S, TABLET_M, TABLET_L). | | isMobileVertical | boolean | Mobile and portrait orientation. | | isMobileHorizontal | boolean | Mobile and landscape orientation. | | isTabletVertical | boolean | Tablet and portrait orientation. | | isTabletHorizontal | boolean | Tablet and landscape orientation. | | isMobileS | boolean | Exactly small mobile (MOBILE_S). | | isMobileM | boolean | Exactly medium mobile (MOBILE_M). | | isMobileL | boolean | Exactly large mobile (MOBILE_L). | | isTabletS | boolean | Exactly small tablet (TABLET_S). | | isTabletM | boolean | Exactly medium tablet (TABLET_M). | | isTabletL | boolean | Exactly large tablet (TABLET_L). | | isLaptop | boolean | Exactly laptop (LAPTOP). | | isDesktop | boolean | Any desktop (DESKTOP). | | isTV | boolean | Exactly TV (TV). | | isTV4K | boolean | Exactly 4K TV (TV_4K). |

Also export:

export enum DEVICE_TYPE {
  MOBILE_S,
  MOBILE_M,
  MOBILE_L,
  TABLET_S,
  TABLET_M,
  TABLET_L,
  LAPTOP,
  DESKTOP,
  TV,
  TV_4K,
}

export const BREAKPOINTS = {
  MOBILE_S_MAX_WIDTH: number,
  MOBILE_MAX_WIDTH: number,
  TABLET_S_MAX_WIDTH: number,
  TABLET_M_MAX_WIDTH: number,
  TABLET_L_MAX_WIDTH: number,
  LAPTOP_MAX_WIDTH: number,
  DESKTOP_MAX_WIDTH: number,
  TV_MAX_WIDTH: number,
};

Contributing

  1. Fork the repo
  2. Create a feature branch (git checkout -b feat/your-feature)
  3. Commit your changes (git commit -m "feat: add ...")
  4. Push to your branch (git push origin feat/your-feature)
  5. Open a Pull Request

Please follow the Conventional Commits standard.

License

MIT © Valentin Röhle