# useragnt

> Useragnt is a JavaScript library that detects device, OS, and browser from User agent. It behaves like a Modernizr.

Latest version **0.6.2** (published 2017-12-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install useragnt
pnpm add useragnt
yarn add useragnt
bun add useragnt
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.2 |
| Published | 2017-12-07 |
| First published | 2016-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Yuichiroh Arai |
| Maintainers | yuichiroharai |

## Links

- npm: https://www.npmjs.com/package/useragnt
- Repository: https://yuichiroharai@github.com/yuichiroharai/Useragnt
- Homepage: https://github.com/yuichiroharai/Useragnt#readme
- Issues: https://github.com/yuichiroharai/Useragnt/issues
- npm.io page: https://npm.io/package/useragnt

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.16.4
- [uglify-js](https://npm.io/package/uglify-js.md) ^2.7.3

## Recent versions

- 0.6.2 (latest) — 2017-12-07
- 0.6.1 — 2016-11-17
- 0.6.0 — 2016-11-17
- 0.5.2 — 2016-11-14
- 0.5.1 — 2016-11-13
- 0.5.0 — 2016-11-13
- 0.4.1 — 2016-10-20
- 0.4.0 — 2016-10-20

## README

# Useragnt
Useragnt is a JavaScript library that detects device, OS, and browser from User agent.

It behaves like a [Modernizr](https://modernizr.com/).


## Install

[![NPM](https://nodei.co/npm/useragnt.png?mini=true)](https://nodei.co/npm/useragnt/)

## Usage

### Custom build

```js
var fs = require("fs");
var useragnt = require("useragnt");

var configAll = {
  "minify": true,
  "classPrefix": "",
  "options": [
    "setClasses"
  ],
  "uaDetects": [
    "mobile",
    "tablet",
    "pc",

    "windows",
    "mac",
    "linux",
    "ios",
    "android",

    "edge",
    "ie",
    "safari",
    "webkit",
    "chrome",
    "firefox",
    "opera",

    "webview"
  ]
}

var result = useragnt.build(configAll);

fs.writeFileSync("./useragnt.min.js", result);
```


### Using Useragnt with CSS

```css
.pc .hoge {
  /*...*/
}
.no-pc .hoge {
  /*...*/
}
```


### Using Useragnt with JavaScript

```js
if (Useragnt.pc) {
  //...
} else {
  //...
}

// OS version
if (Useragnt.windows) logVersion(Useragnt.windows.version, "windows");
if (Useragnt.mac) logVersion(Useragnt.mac.version, "mac");
if (Useragnt.ios) logVersion(Useragnt.ios.version, "ios");
if (Useragnt.android) logVersion(Useragnt.android.version, "android");

// Browser version
if (Useragnt.ie) logVersion(Useragnt.ie.version, "ie");
if (Useragnt.edge) logVersion(Useragnt.edge.version, "edge");
if (Useragnt.safari) logVersion(Useragnt.safari.version, "safari");
if (Useragnt.chrome) logVersion(Useragnt.chrome.version, "chrome");
if (Useragnt.firefox) logVersion(Useragnt.firefox.version, "firefox");
if (Useragnt.opera) logVersion(Useragnt.opera.version, "opera");



function logVersion(version, title) {
  console.log("----- " + title + " -----");
  console.log("str: " + version.str);
  console.log("float: " + version.float);
  console.log("major: " + version.major);
  console.log("minor: " + version.minor);
  console.log("build: " + version.build);
  console.log("revision: " + version.revision);
}
```



## Example
http://codepen.io/yuichiroharai/pen/PzYeZg

---
_Source: https://npm.io/package/useragnt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
