user-agent-detect
v1.1.0
Published
[![npm version](https://img.shields.io/npm/v/user-agent-detector)](https://www.npmjs.com/package/user-agent-detector) [![license](https://img.shields.io/github/license/anuj8126/user-agent-detector)](LICENSE) [![issues](https://img.shields.io/github/issues
Downloads
10
Readme
User-Agent Detector
User-Agent Detector is a lightweight JavaScript/TypeScript library designed to detect device information based on the user agent string. This library provides an easy way to determine whether the client device is mobile, tablet, or desktop, along with other details like operating system, version, and manufacturer.
Features
- Detect if the device is mobile, tablet, or desktop.
- Identify the operating system (Windows, MacOS, Linux, Android, iOS).
- Extract the browser version.
- Determine the device manufacturer (Samsung, Apple, Huawei, Sony, LG).
- Simple React hook for easy integration in React applications.
Installation
You can install the library via npm:
npm install user-agent-detector
Usage
REACT
import React from 'react';
import { useDeviceDetection } from 'user-agent-detect';
const App: React.FC = () => {
const deviceInfo = useDeviceDetection();
return (
<div>
<h1>Device Information</h1>
<p>Is Mobile: {deviceInfo.isMobile.toString()}</p>
<p>Is Tablet: {deviceInfo.isTablet.toString()}</p>
<p>Is Phone: {deviceInfo.isPhone.toString()}</p>
<p>OS: {deviceInfo.os}</p>
<p>Version: {deviceInfo.version}</p>
<p>Manufacturer: {deviceInfo.manufacturer}</p>
<p>Grade: {deviceInfo.grade}</p>
</div>
);
};
General
<script src="https://cdn.jsdelivr.net/npm/user-agent-detect@latest/dist/index.min.js"></script>
<script>
const md = new UserAgentDetect(window.navigator.userAgent);
console.log('Is Mobile:', md.isMobile());
console.log('Is Tablet:', md.isTablet());
console.log('Is Phone:', md.isPhone());
console.log('OS:', md.os());
console.log('Version:', md.version());
console.log('Manufacturer:', md.manufacturer());
console.log('Grade:', md.grade());
</script>
These changes correct the import
path and ensure that the example usage is consistent with the package's actual functionality.