mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-21 01:26:40 +03:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51a808871d |
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"title": "UA-Parser.JS",
|
"title": "UA-Parser.JS",
|
||||||
"name": "ua-parser-js",
|
"name": "ua-parser-js",
|
||||||
"version": "0.5.11",
|
"version": "0.5.0",
|
||||||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"user-agent",
|
"user agent",
|
||||||
"parser",
|
"parser",
|
||||||
"browser",
|
"browser",
|
||||||
"engine",
|
"engine",
|
||||||
@@ -14,10 +14,7 @@
|
|||||||
],
|
],
|
||||||
"homepage": "http://github.com/faisalman/ua-parser-js",
|
"homepage": "http://github.com/faisalman/ua-parser-js",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Faisal Salman <fyzlman@gmail.com>",
|
"Faisal Salman <fyzlman@gmail.com>"
|
||||||
"Christopher De Cairos <chris.decairos@gmail.com>",
|
|
||||||
"John Tantalo <john.tantalo@gmail.com>",
|
|
||||||
"Lee Treveil <leetreveil@gmail.com>"
|
|
||||||
],
|
],
|
||||||
"main": "ua-parser",
|
"main": "ua-parser",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
30
readme.md
30
readme.md
@@ -11,7 +11,7 @@ Lightweight JavaScript-based User-Agent string parser
|
|||||||
|
|
||||||
## Features
|
## 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().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().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"}
|
console.log(parser.getResult().os); // {name: "Ubuntu", version: "11.10"}
|
||||||
|
|
||||||
// let's take another test please
|
// let's take another test please
|
||||||
@@ -88,34 +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.setUA(uaString).getDevice().model); // "PlayBook"
|
||||||
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
|
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
|
||||||
console.log(parser.getEngine().name); // "WebKit"
|
console.log(parser.getEngine().name); // "AppleWebKit"
|
||||||
```
|
|
||||||
|
|
||||||
## Using jQuery
|
|
||||||
|
|
||||||
If you're using jQuery, `$.ua` object will be created automatically based on container's user-agent. To change different user-agent use `$.setUA(uastring)`. In case you need, `UAParser` 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"
|
|
||||||
|
|
||||||
// reset to custom user-agent
|
|
||||||
$.setUA('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
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## 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
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
|||||||
9
test.js
9
test.js
@@ -896,15 +896,6 @@ var os = [
|
|||||||
version : ''
|
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',
|
desc : 'Nintendo',
|
||||||
ua : '',
|
ua : '',
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
{
|
|
||||||
"title": "UA-Parser.JS",
|
|
||||||
"name": "ua-parser-js",
|
|
||||||
"version": "0.5.11",
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
58
ua-parser.js
58
ua-parser.js
@@ -1,8 +1,8 @@
|
|||||||
// UA-Parser.JS v0.5.11
|
// UA-Parser.JS v0.5.1
|
||||||
// Lightweight JavaScript-based User-Agent string parser
|
// Lightweight JavaScript-based User-Agent string parser
|
||||||
// https://github.com/faisalman/ua-parser-js
|
// https://github.com/faisalman/ua-parser-js
|
||||||
//
|
//
|
||||||
// Copyright © 2012-2013 Faisalman
|
// Copyright © 2012 Faisalman
|
||||||
// Dual licensed under GPLv2 & MIT
|
// Dual licensed under GPLv2 & MIT
|
||||||
|
|
||||||
(function (global, undefined) {
|
(function (global, undefined) {
|
||||||
@@ -119,13 +119,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
device : {
|
device : {
|
||||||
sprint : {
|
htc : {
|
||||||
model : {
|
model : {
|
||||||
'Evo Shift 4G' : '7373KT'
|
'Evo Shift 4G' : '7373KT'
|
||||||
},
|
|
||||||
vendor : {
|
|
||||||
'HTC' : 'APA',
|
|
||||||
'Sprint' : 'Sprint'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -168,7 +164,6 @@
|
|||||||
/ms(ie)\s((\d+)?[\w\.]+)/i, // Internet Explorer
|
/ms(ie)\s((\d+)?[\w\.]+)/i, // Internet Explorer
|
||||||
|
|
||||||
// Webkit/KHTML based
|
// 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|ovibrowser|bolt)\/((\d+)?[\w\.-]+)/i
|
||||||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt
|
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt
|
||||||
], [NAME, VERSION, MAJOR], [
|
], [NAME, VERSION, MAJOR], [
|
||||||
@@ -176,9 +171,6 @@
|
|||||||
/(yabrowser)\/((\d+)?[\w\.]+)/i // Yandex
|
/(yabrowser)\/((\d+)?[\w\.]+)/i // Yandex
|
||||||
], [[NAME, 'Yandex'], VERSION, MAJOR], [
|
], [[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|[tizenoka]{5}\s?browser)\/v?((\d+)?[\w\.]+)/i
|
||||||
// Chrome/OmniWeb/Arora/Tizen/Nokia
|
// Chrome/OmniWeb/Arora/Tizen/Nokia
|
||||||
], [NAME, VERSION, MAJOR], [
|
], [NAME, VERSION, MAJOR], [
|
||||||
@@ -206,18 +198,16 @@
|
|||||||
/(navigator|netscape)\/((\d+)?[\w\.-]+)/i // Netscape
|
/(navigator|netscape)\/((\d+)?[\w\.-]+)/i // Netscape
|
||||||
], [[NAME, 'Netscape'], VERSION, MAJOR], [
|
], [[NAME, 'Netscape'], VERSION, MAJOR], [
|
||||||
/(swiftfox)/i, // Swiftfox
|
/(swiftfox)/i, // Swiftfox
|
||||||
/(iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?((\d+)?[\w\.\+]+)/i,
|
/(iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo)[\/\s]?((\d+)?[\w\.\+]+)/i,
|
||||||
// Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
|
// 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)\/((\d+)?[\w\.-]+)/i,
|
||||||
// Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
|
// Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
|
||||||
/(mozilla)\/((\d+)?[\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
|
/(mozilla)\/((\d+)?[\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
/(uc\s?browser|polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf)[\/\s]?((\d+)?[\w\.]+)/i,
|
/(uc\s?browser|polaris|lynx|dillo|icab|doris)[\/\s]?((\d+)?[\w\.]+)/i,
|
||||||
// UCBrowser/Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf
|
// UCBrowser/Polaris/Lynx/Dillo/iCab/Doris
|
||||||
/(links)\s\(((\d+)?[\w\.]+)/i, // Links
|
|
||||||
/(gobrowser)\/?((\d+)?[\w\.]+)*/i, // GoBrowser
|
/(gobrowser)\/?((\d+)?[\w\.]+)*/i, // GoBrowser
|
||||||
/(ice\s?browser)\/v?((\d+)?[\w\._]+)/i, // ICE Browser
|
|
||||||
/(mosaic)[\/\s]((\d+)?[\w\.]+)/i // Mosaic
|
/(mosaic)[\/\s]((\d+)?[\w\.]+)/i // Mosaic
|
||||||
], [NAME, VERSION, MAJOR]
|
], [NAME, VERSION, MAJOR]
|
||||||
],
|
],
|
||||||
@@ -254,13 +244,11 @@
|
|||||||
/(nintendo|playstation)\s([wids3portablev]+)/i // Nintendo/Playstation
|
/(nintendo|playstation)\s([wids3portablev]+)/i // Nintendo/Playstation
|
||||||
], [VENDOR, MODEL, [TYPE, CONSOLE]], [
|
], [VENDOR, MODEL, [TYPE, CONSOLE]], [
|
||||||
|
|
||||||
/(sprint\s(\w+))/i // Sprint Phones
|
/(sprint\sapa)(\w+)/i
|
||||||
], [[VENDOR, mapper.string, maps.device.sprint.vendor], [MODEL, mapper.string, maps.device.sprint.model], [TYPE, MOBILE]], [
|
], [[VENDOR, 'HTC'], [MODEL, mapper.string, maps.device.htc.model], [TYPE, MOBILE]], [
|
||||||
|
|
||||||
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
|
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
|
||||||
/(zte)-(\w+)*/i, // ZTE
|
|
||||||
/(alcatel|geeksphone|huawei|lenovo|nexian|panasonic|;\ssony)[_\s-]?([\w-]+)*/i
|
/(zte)-(\w+)*/i // ZTE
|
||||||
// Alcatel/GeeksPhone/Huawei/Lenovo/Nexian/Panasonic/Sony
|
|
||||||
], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
|
], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
|
||||||
|
|
||||||
/\s((milestone|droid[2x]?))[globa\s]*\sbuild\//i, // Motorola
|
/\s((milestone|droid[2x]?))[globa\s]*\sbuild\//i, // Motorola
|
||||||
@@ -270,7 +258,7 @@
|
|||||||
], [[VENDOR, 'Motorola'], MODEL, [TYPE, TABLET]], [
|
], [[VENDOR, 'Motorola'], MODEL, [TYPE, TABLET]], [
|
||||||
|
|
||||||
/android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n8000|sgh-t8[56]9))/i
|
/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,
|
/((s[cgp]h-\w+|gt-\w+|galaxy\snexus))/i,
|
||||||
/(sam[sung]*)[\s-]*(\w+-?[\w-]*)*/i,
|
/(sam[sung]*)[\s-]*(\w+-?[\w-]*)*/i,
|
||||||
/sec-((sgh\w+))/i
|
/sec-((sgh\w+))/i
|
||||||
@@ -297,11 +285,9 @@
|
|||||||
engine : [[
|
engine : [[
|
||||||
|
|
||||||
/(presto)\/([\w\.]+)/i, // Presto
|
/(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
|
/(khtml)\/([\w\.]+)/i, // KHTML
|
||||||
/(tasman)\s([\w\.]+)/i, // Tasman
|
/(tasman)\s([\w\.]+)/i // Tasman
|
||||||
/(links)\s\(([\w\.]+)/i, // Links
|
|
||||||
/(icab)[\/\s]([2-3]\.[\d\.]+)/i // iCab
|
|
||||||
], [NAME, VERSION], [
|
], [NAME, VERSION], [
|
||||||
|
|
||||||
/rv\:([\w\.]+).*(gecko)/i // Gecko
|
/rv\:([\w\.]+).*(gecko)/i // Gecko
|
||||||
@@ -327,10 +313,7 @@
|
|||||||
], [NAME, VERSION], [
|
], [NAME, VERSION], [
|
||||||
/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]+)*/i // Symbian
|
/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]+)*/i // Symbian
|
||||||
], [[NAME, 'Symbian'], VERSION],[
|
], [[NAME, 'Symbian'], VERSION],[
|
||||||
/mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
|
|
||||||
], [[NAME, 'Firefox OS'], VERSION], [
|
|
||||||
|
|
||||||
// Console
|
|
||||||
/(nintendo|playstation)\s([wids3portablev]+)/i, // Nintendo/Playstation
|
/(nintendo|playstation)\s([wids3portablev]+)/i, // Nintendo/Playstation
|
||||||
|
|
||||||
// GNU/Linux based
|
// GNU/Linux based
|
||||||
@@ -362,8 +345,8 @@
|
|||||||
// Other
|
// Other
|
||||||
/(haiku)\s(\w+)/i, // Haiku
|
/(haiku)\s(\w+)/i, // Haiku
|
||||||
/(aix)\s((\d)(?=\.|\)|\s)[\w\.]*)*/i, // AIX
|
/(aix)\s((\d)(?=\.|\)|\s)[\w\.]*)*/i, // AIX
|
||||||
/(macintosh|mac(?=_powerpc)|plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos)/i,
|
/(macintosh|mac(?=_powerpc)|plan\s9|minix|beos|os\/2|amigaos|morphos)/i,
|
||||||
// Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS
|
// Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS
|
||||||
/(unix)\s?([\w\.]+)*/i // UNIX
|
/(unix)\s?([\w\.]+)*/i // UNIX
|
||||||
], [NAME, VERSION]
|
], [NAME, VERSION]
|
||||||
]
|
]
|
||||||
@@ -419,13 +402,6 @@
|
|||||||
exports.UAParser = UAParser;
|
exports.UAParser = UAParser;
|
||||||
} else {
|
} else {
|
||||||
// browser env
|
// browser env
|
||||||
global.UAParser = UAParser;
|
global['UAParser'] = UAParser;
|
||||||
// jQuery specific
|
|
||||||
if (typeof global.jQuery !== UNDEF) {
|
|
||||||
global.jQuery.ua = new UAParser().getResult();
|
|
||||||
global.jQuery.setUA = function (uastring) {
|
|
||||||
global.jQuery.ua = new UAParser(uastring).getResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})(this);
|
})(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