1.0.0 • Published 2 months ago

@slynhq/ua v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

@slynhq/ua

A lightweight utility package for parsing and handling user agents. This package provides easy access to browser, OS, device, and engine information from user agent strings.

Installation

npm install @slynhq/ua
# or
yarn add @slynhq/ua
# or
pnpm add @slynhq/ua

Usage

import { getUserAgent } from "@slynhq/ua";

// Get user agent information
const userAgentInfo = getUserAgent(userAgentString, screenWidth);

// Example output:
// {
//   os: "Windows",
//   browser: "Chrome",
//   cpu: "x64",
//   engine: "Blink",
//   version: "120.0.0.0",
//   device: "Desktop" // or "Mobile" or "Tablet" based on width
// }

API Reference

getUserAgent(userAgent: string, width?: number)

Parses a user agent string and returns detailed information about the browser, OS, and device.

Parameters

  • userAgent (string): The user agent string to parse
  • width (number, optional): Screen width in pixels to determine device type

Returns

An object containing:

  • os: Operating system name
  • browser: Browser name
  • cpu: CPU architecture
  • engine: Browser engine name
  • version: Engine version
  • device: Device type ("Desktop", "Tablet", or "Mobile")

Device Type Determination

The package determines device type based on the provided width:

  • Mobile: width < 768px
  • Tablet: width >= 768px and < 1024px
  • Desktop: width >= 1024px or no width provided

Requirements

  • Next.js >= 13.0.0
  • Node.js >= 14.0.0

License

MIT © @slynhq

1.0.0

2 months ago