0.6.2 • Published 6 years ago

useragnt v0.6.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Useragnt

Useragnt is a JavaScript library that detects device, OS, and browser from User agent.

It behaves like a Modernizr.

Install

NPM

Usage

Custom build

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

.pc .hoge {
  /*...*/
}
.no-pc .hoge {
  /*...*/
}

Using Useragnt with JavaScript

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

0.6.2

6 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.1

8 years ago

0.4.0

8 years ago