ua-parser-js
Advanced tools
Comparing version 0.5.15 to 0.5.20
{ | ||
"title": "UA-Parser.JS", | ||
"name": "ua-parser-js", | ||
"version": "0.5.15", | ||
"version": "0.5.20", | ||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)", | ||
@@ -25,6 +25,6 @@ "description": "Lightweight JavaScript-based user-agent string parser", | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha -R spec", | ||
"pretest": "./node_modules/uglify-js/bin/uglifyjs ua-parser.js > ua-parser.min.js" | ||
"test": "./node_modules/mocha/bin/mocha -R spec" | ||
}, | ||
"devDependencies": { | ||
"jshint": ">= 1.1.0", | ||
"mocha": ">= 1.7.1", | ||
@@ -58,3 +58,4 @@ "uglify-js": ">= 1.3.4" | ||
"directories": { | ||
"lib": "." | ||
"lib": "src", | ||
"test": "test" | ||
}, | ||
@@ -61,0 +62,0 @@ "files": [ |
152
readme.md
@@ -1,4 +0,4 @@ | ||
# UA-Parser.JS | ||
# UAParser.js | ||
Lightweight JavaScript-based User-Agent string parser | ||
Lightweight JavaScript-based User-Agent string parser. Supports browser & node.js environment. Also available as Component package, Bower package, jQuery.ua, & AMD module | ||
@@ -8,9 +8,8 @@ [![Build Status](https://travis-ci.org/faisalman/ua-parser-js.png)](https://travis-ci.org/faisalman/ua-parser-js) | ||
* Author : Faisalman <<fyzlman@gmail.com>> | ||
* Home : http://faisalman.github.com/ua-parser-js | ||
* Demo : http://faisalman.github.com/ua-parser-js | ||
* Source : https://github.com/faisalman/ua-parser-js | ||
* License : GPLv2 & MIT | ||
## Features | ||
Extract detailed type of web browser, layout engine, operating system, and device purely from user-agent string with relatively lightweight footprint (~7KB minified / ~3KB gzipped). | ||
Extract detailed type of web browser, layout engine, operating system, and device purely from user-agent string with relatively lightweight footprint (~7KB minified / ~3KB gzipped). Written in vanilla js, which means it doesn't depends on any other library. | ||
@@ -22,8 +21,52 @@ ![It's over 9000](https://pbs.twimg.com/media/A9LpEG6CIAA5VrT.jpg) | ||
* `getBrowser()` | ||
* returns `{ name: '', major: '', version: '' }` | ||
``` | ||
# Possible 'browser.name': | ||
Amaya, Arora, Avant, Baidu, Blazer, Bolt, Camino, Chimera, Chrome, Chromium, Comodo Dragon, Conkeror, | ||
Dillo, Dolphin, Doris, Epiphany, Fennec, Firebird, Firefox, Flock, GoBrowser, iCab, ICE Browser, IceApe, IceCat, | ||
Iceweasel, IE [Mobile], Jasmine, K-Meleon, Konqueror, Kindle, Links, Lunascape, Lynx, Maemo, Maxthon, Midori, Minimo, | ||
[Mobile] Safari, Mosaic, Mozilla, Netfront, Netscape, NetSurf, Nokia, OmniWeb, Opera [Mini/Mobi/Tablet], Phoenix, | ||
Polaris, RockMelt, Silk, Skyfire, SeaMonkey, SlimBrowser, Swiftfox, Tizen, UCBrowser, w3m, Yandex | ||
``` | ||
* `getDevice()` | ||
* returns `{ model: '', type: '', vendor: '' }` | ||
``` | ||
# Possible 'device.type': | ||
console, mobile, tablet | ||
# Possible 'device.vendor': | ||
Acer, Alcatel, Apple, Asus, BenQ, BlackBerry, Dell, GeeksPhone, HP, HTC, Huawei, Lenovo, LG, Meizu, Motorola, Nexian, | ||
Nintendo, Nokia, Palm, Panasonic, RIM, Samsung, Siemens, Sony-Ericsson, Sprint, ZTE | ||
``` | ||
* `getEngine()` | ||
* returns `{ name: '', version: '' }` | ||
``` | ||
# Possible 'engine.name' | ||
Amaya, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto, Tasman, Trident, w3m, WebKit | ||
``` | ||
* `getOS()` | ||
* returns `{ name: '', version: '' }` | ||
``` | ||
# Possible 'os.name' | ||
AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS, Fedora, Firefox OS, FreeBSD, Debian, | ||
DragonFly, Gentoo, GNU, Haiku, Hurd, iOS, Joli, Linux, Mac OS, Mandriva, MeeGo, Minix, Mint, Morph OS, NetBSD, | ||
Nintendo, OpenBSD, OS/2, Palm, PCLinuxOS, Plan9, Playstation, QNX, RedHat, RIM Tablet OS, RISC OS, Slackware, | ||
Solaris, SUSE, Symbian, Tizen, Ubuntu, UNIX, WebOS, Windows [Phone/Mobile], Zenwalk | ||
``` | ||
* `getResult()` | ||
* returns `{ browser: {}, device: {}, engine: {}, os: {} }` | ||
* `getUA()` | ||
* returns UA string of current instance | ||
* `setUA(uastring)` | ||
* set & parse UA string | ||
@@ -33,7 +76,10 @@ ## Example | ||
```html | ||
<script type="text/javascript" src="ua-parser.js"></script> | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<script type="text/javascript" src="ua-parser.min.js"></script> | ||
<script type="text/javascript"> | ||
var parser = new UAParser(); | ||
// by default it takes ua string from current browser's window.navigator.userAgent | ||
@@ -66,15 +112,31 @@ console.log(parser.getResult()); | ||
// let's test a custom user-agent string as an example | ||
var uastr = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2"; | ||
parser.setUA(uastr); | ||
console.log(parser.getResult().browser); // {name: "Chromium", major: "15", version: "15.0.874.106"} | ||
console.log(parser.getResult().device); // {model: undefined, type: undefined, vendor: undefined} | ||
console.log(parser.getResult().engine); // {name: "WebKit", version: "535.2"} | ||
console.log(parser.getResult().os); // {name: "Ubuntu", version: "11.10"} | ||
// let's take another test please | ||
console.log(parser.setUA("Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)").getBrowser().name); // "Konqueror" | ||
console.log(parser.getOS()); // {name: "OpenBSD", version: undefined} | ||
console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"} | ||
var uastring = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2"; | ||
parser.setUA(uastring); | ||
var result = parser.getResult(); | ||
// this will also produce the same result (without instantiation): | ||
// var result = UAParser(uastring); | ||
console.log(result.browser); // {name: "Chromium", major: "15", version: "15.0.874.106"} | ||
console.log(result.device); // {model: undefined, type: undefined, vendor: undefined} | ||
console.log(result.os); // {name: "Ubuntu", version: "11.10"} | ||
console.log(result.os.version); // "11.10" | ||
console.log(result.engine.name); // "WebKit" | ||
// do some other tests | ||
var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)"; | ||
console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror" | ||
console.log(parser.getOS()); // {name: "OpenBSD", version: undefined} | ||
console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"} | ||
var uastring3 = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11'; | ||
console.log(parser.setUA(uastring3).getDevice().model); // "PlayBook" | ||
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"} | ||
console.log(parser.getBrowser().name); // "Safari" | ||
</script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> | ||
``` | ||
@@ -84,4 +146,2 @@ | ||
If you're using requirejs, you can load UA-Parser like any other module. | ||
```js | ||
@@ -101,15 +161,29 @@ require(['ua-parser'], function(UAParser) { | ||
```js | ||
var UAParser = require('ua-parser'); | ||
var parser = new UAParser(); | ||
var uaString = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11'; | ||
var UAParser = require('ua-parser'); | ||
var parser = new UAParser(); | ||
console.log(parser.getResult()); | ||
``` | ||
console.log(parser.setUA(uaString).getDevice().model); // "PlayBook" | ||
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"} | ||
console.log(parser.getEngine().name); // "WebKit" | ||
## Using component | ||
```sh | ||
$ component install faisalman/ua-parser-js | ||
``` | ||
## Using jQuery | ||
```js | ||
var UAParser = require('ua-parser-js'); | ||
var parser = new UAParser(); | ||
console.log(parser.getResult()); | ||
``` | ||
If you're using jQuery, `$.ua` object will be created automatically based on container's user-agent. Use `$.ua.get()` / `$.ua.set(uastring)` to get/set user-agent. In case you need, `UAParser` constructor is still present in global though. | ||
## Using bower | ||
```sh | ||
$ bower install ua-parser-js | ||
``` | ||
## Using jQuery.ua | ||
Although written in vanilla js (which means it doesn't depends on jQuery), if you're using jQuery, this library will automatically detect and create `$.ua` object based on browser's user-agent. In case you need, `UAParser` constructor is still present in global though. To get/set user-agent you can use: `$.ua.get()` / `$.ua.set(uastring)`. | ||
```js | ||
@@ -134,4 +208,22 @@ // In browser with default user-agent: 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0': | ||
## Development | ||
Install dependencies | ||
```sh | ||
$ npm install jshint | ||
$ npm install mocha | ||
$ npm install uglify-js | ||
``` | ||
Verify, test, & minify script | ||
```sh | ||
$ ./build/build.sh | ||
``` | ||
## License | ||
Dual licensed under GPLv2 & MIT | ||
Copyright © 2012-2013 Faisalman <<fyzlman@gmail.com>> | ||
@@ -138,0 +230,0 @@ |
{ | ||
"title": "UA-Parser.JS", | ||
"name": "ua-parser-js", | ||
"version": "0.5.15", | ||
"version": "0.5.20", | ||
"description": "Lightweight JavaScript-based user-agent string parser", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"docs": "https://github.com/faisalman/ua-parser-js", | ||
"download": "https://raw.github.com/faisalman/ua-parser-js/master/ua-parser.min.js" | ||
"download": "https://raw.github.com/faisalman/ua-parser-js/master/src/ua-parser.min.js" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
75419
14
1770
233
3
1