2.0.1 • Published 7 months ago

lesca-user-agent v2.0.1

Weekly downloads
4
License
MIT
Repository
-
Last release
7 months ago

NPM React React React React React NPM

Why use it?

Simple browser detection using the user agent.

Live Demo

Installation

npm install lesca-user-agent --save

Usage

location redirect

import UserAgent from 'lesca-user-agent';

if (UserAgent.get() === 'mobile') window.location.replace('./m/');

detect device

import UserAgent from 'lesca-user-agent';

const appIOS = 'https://apps.apple.com/us/app/github/id1477376905';
const appAndroid = 'https://play.google.com/store/apps/details?id=com.github.android';

function download() {
  if (UserAgent.ios()) window.open(appIOS);
  else window.open(appAndroid);
}

<button onClick={download}>download github</button>;

Development

Methods

methoddescriptiondefault
.get(tabletEqualDesktop:boolean):stringget user devicefalse
.facebook():booleanis facebook browser
.line():booleanis Line browser
.ios():booleanis Ios browser
.android():booleanis Android browser
.mac():booleanis Mac browser
.pc():booleanis PC browser

Features

  • maintain if necessary