node-user-agent-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

User Agent Parser

A lightweight and efficient user agent parser for browser, OS, and device detection.

Installation

npm install node-user-agent-parser
# or
yarn add node-user-agent-parser

Usage

ES Modules

import { parseUserAgent } from 'node-user-agent-parser';

const userAgentInfo = parseUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36');
console.log(userAgentInfo);

CommonJS

const { parseUserAgent } = require('node-user-agent-parser');

const userAgentInfo = parseUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36');
console.log(userAgentInfo);

API

parseUserAgent(userAgentString)

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

Parameters:

  • userAgentString (string): The user agent string to parse. If not provided, it will use navigator.userAgent if available.

Returns: An object with the following properties:

{
  browser: {
    name: string;      // Browser name (e.g., 'Chrome', 'Firefox')
    version: string;   // Full version (e.g., '96.0.4664.110')
    major: string;     // Major version (e.g., '96')
  },
  os: {
    name: string;      // OS name (e.g., 'Windows', 'macOS')
    version: string;   // OS version (e.g., '10', '11.6')
  },
  device: {
    type: 'mobile' | 'tablet' | 'desktop' | 'unknown';
    vendor: string;    // Device manufacturer (e.g., 'Apple', 'Samsung')
    model: string;     // Device model if available
  },
  engine: {
    name: string;      // Browser engine (e.g., 'WebKit', 'Gecko')
    version: string;   // Engine version
  },
  ua: string;          // Original user agent string
}

License

MIT

Package Sidebar

Install

npm i node-user-agent-parser

Weekly Downloads

9

Version

1.0.0

License

MIT

Unpacked Size

28.6 kB

Total Files

12

Last publish

Collaborators

  • zobayerhossainmamun