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

@ananay-nag/web-device-info

v1.0.0

Published

Universal web screen/device info (JS, React, Vue3, Angular, Svelte) with real-time updates

Readme

🌐 web-device-info Version

Universal Web Device Information Library – works for JS, React, Angular, Vue3, Svelte.
Detect screen size, orientation, diagonal, platform, language, online status in real-time across all major frameworks.


🚀 Features

  • ✅ Multi-framework support: React, Angular, Vue3, Svelte, Vanilla JS, Common JS
  • ✅ Real-time updates on resize, orientation, and online/offline changes
  • ✅ Screen width, height, and approximate diagonal size (inches)
  • ✅ Orientation detection: portrait / landscape
  • ✅ User agent, platform, language detection
  • ✅ TypeScript ready, fully typed
  • ✅ Tiny & dependency-free (~10 KB)
  • ✅ Hooks / composables for modern frameworks

Version

Version:

  • latest : Version
  • v1.0.0 : Version

📦 Installation

# npm
npm install @ananay-nag/web-device-info

# yarn
yarn add @ananay-nag/web-device-info

# pnpm
pnpm add @ananay-nag/web-device-info

🛠 Usage Examples

1️⃣ React

import React from "react";
import { ReactDeviceInfo } from "@ananay-nag/web-device-info";

const { useDeviceInfo } = ReactDeviceInfo;

export default function App() {
  const deviceInfo = useDeviceInfo({ useViewport: true });

  return (
    <div>
      <h1>React Device Info</h1>
      <pre>{JSON.stringify(deviceInfo, null, 2)}</pre>
    </div>
  );
}

2️⃣ Angular

import { Component, OnInit } from "@angular/core";
import { AngularDeviceInfo } from "@ananay-nag/web-device-info";

@Component({
  selector: "app-root",
  template: `
    <h1>Angular Device Info</h1>
    <pre>{{ deviceInfo | json }}</pre>
  `
})
export class AppComponent implements OnInit {
  deviceInfo: any;

  ngOnInit() {
    this.deviceInfo = AngularDeviceInfo.getDeviceInfo({ useViewport: true });
  }
}

3️⃣ Vue 3

<script setup lang="ts">
import { VueDeviceInfo } from "@ananay-nag/web-device-info";

const { useDeviceInfo } = VueDeviceInfo;
const deviceInfo = useDeviceInfo({ useViewport: true });
</script>

<template>
  <h1>Vue 3 Device Info</h1>
  <pre>{{ deviceInfo }}</pre>
</template>

4️⃣ Svelte

<script lang="ts">
  import { SvelteDeviceInfo } from "@ananay-nag/web-device-info";
  const { deviceInfo } = SvelteDeviceInfo.useDeviceInfo({ useViewport: true });
</script>

<h1>Svelte Device Info</h1>
<pre>{JSON.stringify($deviceInfo, null, 2)}</pre>

5️⃣ Vanilla JS

import { JSDeviceInfo } from "@ananay-nag/web-device-info";

const { getDeviceInfo } = JSDeviceInfo;
console.log("Device Info:", getDeviceInfo({ useViewport: true }));

📋 API Reference

DeviceOptions

| Option | Type | Default | Description | | ------------- | ------- | ------- | ---------------------------------------------------------------------------- | | useViewport | boolean | false | Use window.innerWidth/innerHeight instead of screen.width/screen.height. |

DeviceInfo

| Field | Type | Description | | ------------- | ------------------------- | -------------------------------- | | width | number | Screen width in pixels | | height | number | Screen height in pixels | | diagonal | number | Approximate diagonal in inches | | orientation | "portrait" | "landscape" | Screen orientation | | userAgent | string | Browser user agent | | platform | string | Platform (e.g., Win32, MacIntel) | | language | string | Browser language | | online | boolean | Online/offline status |

Exports

import {
  IDeviceInfo,
  IDeviceOptions,
  getDeviceInfo,   // Core JS API
  onDeviceChange,  // Listen to resize/orientation changes
  ReactDeviceInfo, // React hook
  AngularDeviceInfo,
  VueDeviceInfo,
  SvelteDeviceInfo,
  JSDeviceInfo
} from "@ananay-nag/web-device-info";

🔄 Orientation Change Example

import { onDeviceChange } from "@ananay-nag/web-device-info";

onDeviceChange((info) => {
  console.log("Device changed:", info.orientation, info.width, info.height);
});

💡 Advantages Compared to Other Packages

| Feature / Package | web-device-info | react-device-detect | ua-parser-js | detect.js | | ---------------------------------- | --------------- | ------------------- | ------------ | --------- | | Multi-framework support | ✅ | ❌ | ❌ | ❌ | | Real-time updates | ✅ | ❌ | ❌ | ❌ | | Screen dimensions (width & height) | ✅ | ✅ | ✅ | ✅ | | Screen diagonal size | ✅ | ❌ | ❌ | ❌ | | Orientation detection | ✅ | ❌ | ❌ | ❌ | | Online/offline status | ✅ | ❌ | ❌ | ❌ | | TypeScript ready | ✅ | ✅ | ✅ | ❌ | | Tiny & dependency-free | ✅ | ❌ | ❌ | ❌ | | Hooks / composables | ✅ | ✅ | ❌ | ❌ | | Vanilla JS support | ✅ | ❌ | ✅ | ✅ |

Key Advantages:

  • One library for all major frameworks

  • Automatically updates on screen, orientation, and online status changes

  • sreen diagonal calculation — unique among similar libraries

  • Minimal bundle size for production apps

  • Fully TypeScript ready

  • Unified API across frameworks

📜 License

MIT © 2025 – Open Source ❤️