lesca-user-agent
Version:
simple detect device userAgent
64 lines (44 loc) • 2.48 kB
Markdown
[](https://www.npmjs.com/)
[](https://nodejs.org/en/)
[](https://zh-hant.reactjs.org/)
[](https://lesscss.org/)
[](https://www.w3schools.com/html/)
[](https://www.w3schools.com/css/)
[](https://www.npmjs.com/~jameshsu1125)
Simple browser detection using the user agent.
```sh
npm install lesca-user-agent --save
```
location redirect
```javascript
import UserAgent from 'lesca-user-agent';
if (UserAgent.get() === 'mobile') window.location.replace('./m/');
```
detect device
```JSX
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>;
```
| method | description | default |
| :-------------------------------------------------- | :-----------------: | ------: |
| .**get**(**tabletEqualDesktop**:_boolean_):_string_ | get user device | false |
| .**facebook**():_boolean_ | is facebook browser | |
| .**line**():_boolean_ | is Line browser | |
| .**ios**():_boolean_ | is Ios browser | |
| .**android**():_boolean_ | is Android browser | |
| .**mac**():_boolean_ | is Mac browser | |
| .**pc**():_boolean_ | is PC browser | |
- maintain if necessary