mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-20 09:06:42 +03:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51a808871d |
10
package.json
10
package.json
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"title": "UA-Parser.JS",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.5.15",
|
||||
"version": "0.5.0",
|
||||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
"user-agent",
|
||||
"user agent",
|
||||
"parser",
|
||||
"browser",
|
||||
"engine",
|
||||
@@ -14,11 +14,7 @@
|
||||
],
|
||||
"homepage": "http://github.com/faisalman/ua-parser-js",
|
||||
"contributors": [
|
||||
"Faisal Salman <fyzlman@gmail.com>",
|
||||
"Christopher De Cairos <chris.decairos@gmail.com>",
|
||||
"John Tantalo <john.tantalo@gmail.com>",
|
||||
"Jon Buckley <jon@jbuckley.ca>",
|
||||
"Lee Treveil <leetreveil@gmail.com>"
|
||||
"Faisal Salman <fyzlman@gmail.com>"
|
||||
],
|
||||
"main": "ua-parser",
|
||||
"scripts": {
|
||||
|
||||
42
readme.md
42
readme.md
@@ -11,7 +11,7 @@ Lightweight JavaScript-based User-Agent string parser
|
||||
|
||||
## 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.
|
||||
|
||||

|
||||
|
||||
@@ -65,7 +65,7 @@ Extract detailed type of web browser, layout engine, operating system, and devic
|
||||
|
||||
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().engine); // {name: "AppleWebKit", version: "535.2"}
|
||||
console.log(parser.getResult().os); // {name: "Ubuntu", version: "11.10"}
|
||||
|
||||
// let's take another test please
|
||||
@@ -75,17 +75,6 @@ Extract detailed type of web browser, layout engine, operating system, and devic
|
||||
</script>
|
||||
```
|
||||
|
||||
## Using requirejs
|
||||
|
||||
If you're using requirejs, you can load UA-Parser like any other module.
|
||||
|
||||
```js
|
||||
require(['ua-parser'], function(UAParser) {
|
||||
var parser = new UAParser();
|
||||
console.log(parser.getResult());
|
||||
});
|
||||
```
|
||||
|
||||
## Using node.js
|
||||
|
||||
```sh
|
||||
@@ -99,35 +88,12 @@ var uaString = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWe
|
||||
|
||||
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 jQuery
|
||||
|
||||
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.
|
||||
|
||||
```js
|
||||
// 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':
|
||||
|
||||
// Do some tests
|
||||
console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
|
||||
console.log($.ua.os); // {name: "Android", version: "2.3.4"}
|
||||
console.log($.ua.os.name); // "Android"
|
||||
console.log($.ua.get()); // "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0"
|
||||
|
||||
// reset to custom user-agent
|
||||
$.ua.set('Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; Xoom Build/HWI69) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13');
|
||||
|
||||
// Test again
|
||||
console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"}
|
||||
console.log($.ua.engine.name); // "Webkit"
|
||||
console.log($.ua.browser.version); // "4.0"
|
||||
console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
|
||||
console.log(parser.getEngine().name); // "AppleWebKit"
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2012-2013 Faisalman <<fyzlman@gmail.com>>
|
||||
Copyright © 2012 Faisalman <<fyzlman@gmail.com>>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
||||
28
test.js
28
test.js
@@ -462,16 +462,6 @@ var browsers = [
|
||||
major : '11'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Opera Webkit',
|
||||
ua : 'Mozilla/5.0 AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.123 Mobile Safari/537.22 OPR/14.0.1025.52315',
|
||||
expect :
|
||||
{
|
||||
name : 'Opera',
|
||||
version : '14.0.1025.52315',
|
||||
major : '14'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Opera Mini',
|
||||
ua : 'Opera/9.80 (J2ME/MIDP; Opera Mini/5.1.21214/19.916; U; en) Presto/2.5.25',
|
||||
@@ -807,15 +797,6 @@ var os = [
|
||||
version : '7.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Windows Phone 8',
|
||||
ua : 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; HTC; Windows Phone 8X by HTC)',
|
||||
expect :
|
||||
{
|
||||
name : 'Windows Phone',
|
||||
version : '8.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'BlackBerry',
|
||||
ua : 'BlackBerry9300/5.0.0.912 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/378',
|
||||
@@ -915,15 +896,6 @@ var os = [
|
||||
version : ''
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Firefox OS',
|
||||
ua : 'Mozilla/5.0 (Mobile; rv:14.0) Gecko/14.0 Firefox/14.0',
|
||||
expect :
|
||||
{
|
||||
name : 'Firefox OS',
|
||||
version : undefined
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Nintendo',
|
||||
ua : '',
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"title": "UA-Parser.JS",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.5.15",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
"user-agent",
|
||||
"parser",
|
||||
"browser",
|
||||
"engine",
|
||||
"os",
|
||||
"device"
|
||||
],
|
||||
"homepage": "https://faisalman.github.com/ua-parser-js",
|
||||
"author": {
|
||||
"name": "Faisal Salman",
|
||||
"email": "fyzlman@gmail.com"
|
||||
},
|
||||
"dependencies": {
|
||||
"jquery": ">=1.5"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://www.opensource.org/licenses/mit-license.php"
|
||||
}
|
||||
],
|
||||
"bugs": "https://github.com/faisalman/ua-parser-js/issues",
|
||||
"docs": "https://github.com/faisalman/ua-parser-js",
|
||||
"download": "https://raw.github.com/faisalman/ua-parser-js/master/ua-parser.min.js"
|
||||
}
|
||||
78
ua-parser.js
78
ua-parser.js
@@ -1,8 +1,8 @@
|
||||
// UA-Parser.JS v0.5.15
|
||||
// UA-Parser.JS v0.5.1
|
||||
// Lightweight JavaScript-based User-Agent string parser
|
||||
// https://github.com/faisalman/ua-parser-js
|
||||
//
|
||||
// Copyright © 2012-2013 Faisalman
|
||||
// Copyright © 2012 Faisalman
|
||||
// Dual licensed under GPLv2 & MIT
|
||||
|
||||
(function (global, undefined) {
|
||||
@@ -119,13 +119,9 @@
|
||||
},
|
||||
|
||||
device : {
|
||||
sprint : {
|
||||
htc : {
|
||||
model : {
|
||||
'Evo Shift 4G' : '7373KT'
|
||||
},
|
||||
vendor : {
|
||||
'HTC' : 'APA',
|
||||
'Sprint' : 'Sprint'
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -157,11 +153,6 @@
|
||||
/(opera).+version\/((\d+)?[\w\.]+)/i, // Opera > 9.80
|
||||
/(opera)[\/\s]+((\d+)?[\w\.]+)/i, // Opera < 9.80
|
||||
|
||||
], [NAME, VERSION, MAJOR], [
|
||||
|
||||
/\s(opr)\/((\d+)?[\w\.]+)/i // Opera Webkit
|
||||
], [[NAME, 'Opera'], VERSION, MAJOR], [
|
||||
|
||||
// Mixed
|
||||
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
|
||||
/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?((\d+)?[\w\.]+)*/i,
|
||||
@@ -173,7 +164,6 @@
|
||||
/ms(ie)\s((\d+)?[\w\.]+)/i, // Internet Explorer
|
||||
|
||||
// Webkit/KHTML based
|
||||
/(rekonq)((?:\/)[\w\.]+)*/i, // Rekonq
|
||||
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt)\/((\d+)?[\w\.-]+)/i
|
||||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt
|
||||
], [NAME, VERSION, MAJOR], [
|
||||
@@ -181,9 +171,6 @@
|
||||
/(yabrowser)\/((\d+)?[\w\.]+)/i // Yandex
|
||||
], [[NAME, 'Yandex'], VERSION, MAJOR], [
|
||||
|
||||
/(comodo_dragon)\/((\d+)?[\w\.]+)/i // Comodo Dragon
|
||||
], [[NAME, /_/g, ' '], VERSION, MAJOR], [
|
||||
|
||||
/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?((\d+)?[\w\.]+)/i
|
||||
// Chrome/OmniWeb/Arora/Tizen/Nokia
|
||||
], [NAME, VERSION, MAJOR], [
|
||||
@@ -211,18 +198,16 @@
|
||||
/(navigator|netscape)\/((\d+)?[\w\.-]+)/i // Netscape
|
||||
], [[NAME, 'Netscape'], VERSION, MAJOR], [
|
||||
/(swiftfox)/i, // Swiftfox
|
||||
/(iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?((\d+)?[\w\.\+]+)/i,
|
||||
// Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
|
||||
/(iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo)[\/\s]?((\d+)?[\w\.\+]+)/i,
|
||||
// Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo
|
||||
/(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix)\/((\d+)?[\w\.-]+)/i,
|
||||
// Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
|
||||
/(mozilla)\/((\d+)?[\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
|
||||
|
||||
// Other
|
||||
/(uc\s?browser|polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf)[\/\s]?((\d+)?[\w\.]+)/i,
|
||||
// UCBrowser/Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf
|
||||
/(links)\s\(((\d+)?[\w\.]+)/i, // Links
|
||||
/(uc\s?browser|polaris|lynx|dillo|icab|doris)[\/\s]?((\d+)?[\w\.]+)/i,
|
||||
// UCBrowser/Polaris/Lynx/Dillo/iCab/Doris
|
||||
/(gobrowser)\/?((\d+)?[\w\.]+)*/i, // GoBrowser
|
||||
/(ice\s?browser)\/v?((\d+)?[\w\._]+)/i, // ICE Browser
|
||||
/(mosaic)[\/\s]((\d+)?[\w\.]+)/i // Mosaic
|
||||
], [NAME, VERSION, MAJOR]
|
||||
],
|
||||
@@ -259,13 +244,11 @@
|
||||
/(nintendo|playstation)\s([wids3portablev]+)/i // Nintendo/Playstation
|
||||
], [VENDOR, MODEL, [TYPE, CONSOLE]], [
|
||||
|
||||
/(sprint\s(\w+))/i // Sprint Phones
|
||||
], [[VENDOR, mapper.string, maps.device.sprint.vendor], [MODEL, mapper.string, maps.device.sprint.model], [TYPE, MOBILE]], [
|
||||
|
||||
/(sprint\sapa)(\w+)/i
|
||||
], [[VENDOR, 'HTC'], [MODEL, mapper.string, maps.device.htc.model], [TYPE, MOBILE]], [
|
||||
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
|
||||
/(zte)-(\w+)*/i, // ZTE
|
||||
/(alcatel|geeksphone|huawei|lenovo|nexian|panasonic|;\ssony)[_\s-]?([\w-]+)*/i
|
||||
// Alcatel/GeeksPhone/Huawei/Lenovo/Nexian/Panasonic/Sony
|
||||
|
||||
/(zte)-(\w+)*/i // ZTE
|
||||
], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
|
||||
|
||||
/\s((milestone|droid[2x]?))[globa\s]*\sbuild\//i, // Motorola
|
||||
@@ -275,7 +258,7 @@
|
||||
], [[VENDOR, 'Motorola'], MODEL, [TYPE, TABLET]], [
|
||||
|
||||
/android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n8000|sgh-t8[56]9))/i
|
||||
], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
|
||||
], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
|
||||
/((s[cgp]h-\w+|gt-\w+|galaxy\snexus))/i,
|
||||
/(sam[sung]*)[\s-]*(\w+-?[\w-]*)*/i,
|
||||
/sec-((sgh\w+))/i
|
||||
@@ -302,11 +285,9 @@
|
||||
engine : [[
|
||||
|
||||
/(presto)\/([\w\.]+)/i, // Presto
|
||||
/(webkit|trident|netfront|netsurf|amaya|lynx|w3m)\/([\w\.]+)/i, // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m
|
||||
/(webkit|trident|netfront)\/([\w\.]+)/i, // WebKit/Trident/NetFront
|
||||
/(khtml)\/([\w\.]+)/i, // KHTML
|
||||
/(tasman)\s([\w\.]+)/i, // Tasman
|
||||
/(links)\s\(([\w\.]+)/i, // Links
|
||||
/(icab)[\/\s]([2-3]\.[\d\.]+)/i // iCab
|
||||
/(tasman)\s([\w\.]+)/i // Tasman
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/rv\:([\w\.]+).*(gecko)/i // Gecko
|
||||
@@ -317,7 +298,7 @@
|
||||
|
||||
// Windows based
|
||||
/(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
|
||||
/(windows\sphone(?:\sos)*|windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
|
||||
/(windows\sphone\sos|windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
|
||||
], [NAME, [VERSION, mapper.string, maps.os.windows.version]], [
|
||||
/(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
|
||||
], [[NAME, 'Windows'], [VERSION, mapper.string, maps.os.windows.version]], [
|
||||
@@ -332,10 +313,7 @@
|
||||
], [NAME, VERSION], [
|
||||
/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]+)*/i // Symbian
|
||||
], [[NAME, 'Symbian'], VERSION],[
|
||||
/mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
|
||||
], [[NAME, 'Firefox OS'], VERSION], [
|
||||
|
||||
// Console
|
||||
/(nintendo|playstation)\s([wids3portablev]+)/i, // Nintendo/Playstation
|
||||
|
||||
// GNU/Linux based
|
||||
@@ -367,8 +345,8 @@
|
||||
// Other
|
||||
/(haiku)\s(\w+)/i, // Haiku
|
||||
/(aix)\s((\d)(?=\.|\)|\s)[\w\.]*)*/i, // AIX
|
||||
/(macintosh|mac(?=_powerpc)|plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos)/i,
|
||||
// Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS
|
||||
/(macintosh|mac(?=_powerpc)|plan\s9|minix|beos|os\/2|amigaos|morphos)/i,
|
||||
// Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS
|
||||
/(unix)\s?([\w\.]+)*/i // UNIX
|
||||
], [NAME, VERSION]
|
||||
]
|
||||
@@ -422,28 +400,8 @@
|
||||
exports = module.exports = UAParser;
|
||||
}
|
||||
exports.UAParser = UAParser;
|
||||
} else if (typeof define === FUNC && define.amd) {
|
||||
// requirejs env
|
||||
define(function() {
|
||||
return UAParser;
|
||||
});
|
||||
} else {
|
||||
// browser env
|
||||
global.UAParser = UAParser;
|
||||
// jQuery specific
|
||||
if (typeof global.jQuery !== UNDEF) {
|
||||
var parser = new UAParser();
|
||||
global.jQuery.ua = parser.getResult();
|
||||
global.jQuery.ua.get = function() {
|
||||
return parser.getUA();
|
||||
};
|
||||
global.jQuery.ua.set = function(uastring) {
|
||||
parser.setUA(uastring);
|
||||
var result = parser.getResult();
|
||||
for (var prop in result) {
|
||||
global.jQuery.ua[prop] = result[prop];
|
||||
}
|
||||
};
|
||||
}
|
||||
global['UAParser'] = UAParser;
|
||||
}
|
||||
})(this);
|
||||
|
||||
6
ua-parser.min.js
vendored
6
ua-parser.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user