mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-20 01:04:30 +03:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
992e829643 | ||
|
|
e9e5467add | ||
|
|
d3a2e1750b | ||
|
|
29d75c994e | ||
|
|
7e23d53e4b | ||
|
|
892476f544 | ||
|
|
a165e152de | ||
|
|
ab64c21a80 | ||
|
|
5da2305369 | ||
|
|
1b957cad1a | ||
|
|
8d9cd21331 | ||
|
|
f117f600ba | ||
|
|
978ee5a4da | ||
|
|
a3e4fbe5bb | ||
|
|
9dacf37e4a | ||
|
|
4d99bc0777 | ||
|
|
f558e657bb | ||
|
|
4203f8144f | ||
|
|
21a525f442 | ||
|
|
3abf465aec | ||
|
|
56c90d2134 | ||
|
|
dc6bae6aae |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.7.7",
|
||||
"version": "0.7.9",
|
||||
"authors": [
|
||||
"Faisal Salman <fyzlman@gmail.com>"
|
||||
],
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# dependencies
|
||||
JSHINT_DIR="node_modules/jshint/bin/jshint"
|
||||
MOCHA_DIR="node_modules/mocha/bin/mocha"
|
||||
UGLIFY_DIR="node_modules/uglify-js/bin/uglifyjs"
|
||||
|
||||
# check module directory & install if not found
|
||||
function check_module {
|
||||
if ! type $2 &> /dev/null
|
||||
then
|
||||
echo "$2 is not found"
|
||||
if ! type "npm" &> /dev/null
|
||||
then
|
||||
echo "npm is not installed"
|
||||
echo "Exiting"
|
||||
exit 1
|
||||
else
|
||||
echo "Installing $1..."
|
||||
npm install $1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
check_module "jshint" $JSHINT_DIR
|
||||
check_module "mocha" $MOCHA_DIR
|
||||
check_module "uglify-js" $UGLIFY_DIR
|
||||
|
||||
echo "Verifiying code..."
|
||||
$JSHINT_DIR src/ua-parser.js
|
||||
|
||||
echo "Running test..."
|
||||
$MOCHA_DIR -R nyan test/test.js
|
||||
|
||||
echo "Minifying script..."
|
||||
$UGLIFY_DIR src/ua-parser.js > dist/ua-parser.min.js --comments '/UAParser\.js/'
|
||||
echo "OK"
|
||||
112
build/verup.js
112
build/verup.js
@@ -1,112 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Increment and update version in all project files.
|
||||
*
|
||||
* Ussage:
|
||||
*
|
||||
* Increment revision by 1:
|
||||
* node verup.js 1
|
||||
*
|
||||
* Increment minor version by 1:
|
||||
* node verup.js 1.0
|
||||
*
|
||||
* Increment major version by 1:
|
||||
* node verup.js 1.0.0
|
||||
*
|
||||
*
|
||||
* @author Dumitru Uzun (DUzun.Me)
|
||||
* @version 1.1.0
|
||||
*/
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
var _root = path.join(__dirname, '..');
|
||||
var files = [
|
||||
'ua-parser-js.jquery.json',
|
||||
'component.json',
|
||||
'bower.json',
|
||||
'package.js',
|
||||
'src/ua-parser.js'
|
||||
];
|
||||
|
||||
var ver_reg = [
|
||||
/^((?:\$|@|(\s*(?:var|,)?\s+))(?:LIBVERSION|version)[\s\:='"]+)([0-9]+(?:\.[0-9]+){2,2})/
|
||||
, /^(\s?\*.*v)([0-9]+(?:\.[0-9]+){2,2})/
|
||||
];
|
||||
|
||||
var packFile = path.join(_root, 'package.json');
|
||||
var packo = require(packFile);
|
||||
|
||||
if ( !packo ) {
|
||||
console.error('Can\'t read package.json file');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var over = packo.version;
|
||||
|
||||
/*
|
||||
* bump should be 1 for revision, 1.0 for minor and 1.0.0 for major version
|
||||
*/
|
||||
var bump = (process.argv[2] || '1').split('.').reverse();
|
||||
|
||||
if ( over ) {
|
||||
var nver = over.split('.').reverse();
|
||||
var b, l;
|
||||
while(bump.length && !(b = parseInt(bump.pop())));
|
||||
l = bump.length;
|
||||
|
||||
// console.log({b:b,nver:nver,over:over,l:l,bump:bump})
|
||||
nver[l] = +nver[l] + b;
|
||||
bump.forEach(function (v,i) { nver[i] = v; });
|
||||
|
||||
nver = nver.reverse().join('.');
|
||||
packo.version = nver;
|
||||
|
||||
console.log('Bumping version: ' + over + ' -> ' + nver);
|
||||
|
||||
var buf = JSON.stringify(packo, null, 2);
|
||||
|
||||
if ( buf && over != nver ) {
|
||||
buf += "\n";
|
||||
fs.writeFileSync(packFile, buf);
|
||||
}
|
||||
|
||||
files.forEach(function (f) {
|
||||
var fn = path.join(_root, f);
|
||||
var cnt = fs.readFileSync(fn, 'utf8');
|
||||
var ext = path.extname(f);
|
||||
var buf;
|
||||
|
||||
switch(ext) {
|
||||
case '.json': {
|
||||
var packo = JSON.parse(cnt);
|
||||
packo.version = nver;
|
||||
buf = JSON.stringify(packo, null, 2);
|
||||
if ( buf ) {
|
||||
buf += "\n";
|
||||
}
|
||||
} break;
|
||||
|
||||
default: {
|
||||
buf = cnt
|
||||
.split('\n')
|
||||
.map(function (l) {
|
||||
for(var i=ver_reg.length; i--;) {
|
||||
if ( ver_reg[i].test(l) ) {
|
||||
return l.replace(ver_reg[i], function ($0,$1) { return $1 + nver })
|
||||
}
|
||||
}
|
||||
return l;
|
||||
})
|
||||
.join("\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
if ( buf && buf != cnt ) {
|
||||
console.log("\t" + fn.replace(_root, ''));
|
||||
fs.writeFileSync(fn, buf);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.7.7",
|
||||
"version": "0.7.9",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
"user-agent",
|
||||
|
||||
4
dist/ua-parser.min.js
vendored
4
dist/ua-parser.min.js
vendored
File diff suppressed because one or more lines are too long
9
dist/ua-parser.pack.js
vendored
Normal file
9
dist/ua-parser.pack.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
Package.describe({
|
||||
name: 'faisalman:ua-parser-js',
|
||||
version: '0.7.7',
|
||||
version: '0.7.9',
|
||||
summary: 'Lightweight JavaScript-based user-agent string parser',
|
||||
git: 'https://github.com/faisalman/ua-parser-js.git',
|
||||
documentation: 'readme.md'
|
||||
|
||||
24
package.json
24
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"title": "UAParser.js",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.7.7",
|
||||
"version": "0.7.9",
|
||||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
@@ -42,13 +42,29 @@
|
||||
],
|
||||
"main": "src/ua-parser.js",
|
||||
"scripts": {
|
||||
"test": "./build/build.sh",
|
||||
"verup": "node ./build/verup.js"
|
||||
"build": "uglifyjs src/ua-parser.js > dist/ua-parser.min.js --comments '/UAParser\\.js/' && uglifyjs src/ua-parser.js > dist/ua-parser.pack.js --comments '/UAParser\\.js/' --compress --mangle",
|
||||
"test": "jshint src/ua-parser.js && mocha -R nyan test/test.js",
|
||||
"verup": "node ./node_modules/verup",
|
||||
"version": "node ./node_modules/verup 0"
|
||||
},
|
||||
"verup": {
|
||||
"files": [
|
||||
"ua-parser-js.jquery.json",
|
||||
"component.json",
|
||||
"bower.json",
|
||||
"package.js",
|
||||
"src/ua-parser.js"
|
||||
],
|
||||
"regs": [
|
||||
"^((?:\\$|(\\s*\\*\\s*@)|(\\s*(?:var|,)?\\s+))(?:LIBVERSION|version)[\\s\\:='\"]+)([0-9]+(?:\\.[0-9]+){2,2})",
|
||||
"^(\\s?\\*.*v)([0-9]+(?:\\.[0-9]+){2,2})"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"jshint": "~1.1.0",
|
||||
"mocha": "~1.8.0",
|
||||
"uglify-js": "~1.3.4"
|
||||
"uglify-js": "~1.3.4",
|
||||
"verup": "^1.3.x"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
73
readme.md
73
readme.md
@@ -1,8 +1,9 @@
|
||||
# UAParser.js
|
||||
|
||||
Lightweight JavaScript-based User-Agent string parser. Supports browser & node.js environment. Also available as jQuery/Zepto plugin, Component package, Bower package, Meteor package, & AMD module
|
||||
Lightweight JavaScript-based User-Agent string parser. Supports browser & node.js environment. Also available as jQuery/Zepto plugin, Component/Bower/Meteor package, & RequireJS/AMD module
|
||||
|
||||
[](https://travis-ci.org/faisalman/ua-parser-js)
|
||||
[](http://flattr.com/thing/3867907/faisalmanua-parser-js-on-GitHub)
|
||||
|
||||
* Author : Faisal Salman <<fyzlman@gmail.com>>
|
||||
* Demo : http://faisalman.github.io/ua-parser-js
|
||||
@@ -17,20 +18,20 @@ Extract detailed type of web browser, layout engine, operating system, cpu archi
|
||||
## Methods
|
||||
|
||||
* `getBrowser()`
|
||||
* returns `{ name: '', major: '', version: '' }`
|
||||
* returns `{ name: '', version: '' }`
|
||||
|
||||
```
|
||||
# Possible 'browser.name':
|
||||
Amaya, Android Browser, 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, IceDragon,
|
||||
Chromium, Comodo Dragon, Conkeror, Dillo, Dolphin, Doris, Edge, Epiphany, Fennec,
|
||||
Firebird, Firefox, Flock, GoBrowser, iCab, ICE Browser, IceApe, IceCat, IceDragon,
|
||||
Iceweasel, IE [Mobile], Iron, Jasmine, K-Meleon, Konqueror, Kindle, Links,
|
||||
Lunascape, Lynx, Maemo, Maxthon, Midori, Minimo, MIUI Browser, [Mobile] Safari,
|
||||
Mosaic, Mozilla, Netfront, Netscape, NetSurf, Nokia, OmniWeb, Opera [Mini/Mobi/Tablet],
|
||||
Phoenix, Polaris, QQBrowser, RockMelt, Silk, Skyfire, SeaMonkey, SlimBrowser, Swiftfox,
|
||||
Tizen, UCBrowser, Vivaldi, w3m, Yandex
|
||||
|
||||
# 'browser.version' & 'browser.major' determined dynamically
|
||||
# 'browser.version' determined dynamically
|
||||
```
|
||||
|
||||
* `getDevice()`
|
||||
@@ -54,8 +55,8 @@ Siemens, Sony-Ericsson, Sprint, Xbox, ZTE
|
||||
|
||||
```
|
||||
# Possible 'engine.name'
|
||||
Amaya, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto, Tasman,
|
||||
Trident, w3m, WebKit
|
||||
Amaya, EdgeHTML, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto,
|
||||
Tasman, Trident, w3m, WebKit
|
||||
|
||||
# 'engine.version' determined dynamically
|
||||
```
|
||||
@@ -112,8 +113,7 @@ ppc, sparc, sparc64
|
||||
ua: "",
|
||||
browser: {
|
||||
name: "",
|
||||
version: "",
|
||||
major: ""
|
||||
version: ""
|
||||
},
|
||||
engine: {
|
||||
name: "",
|
||||
@@ -142,7 +142,7 @@ ppc, sparc, sparc64
|
||||
// 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.browser); // {name: "Chromium", 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"
|
||||
@@ -167,20 +167,6 @@ ppc, sparc, sparc64
|
||||
</html>
|
||||
```
|
||||
|
||||
### Extending regex patterns
|
||||
|
||||
* `UAParser(uastring[, extensions])`
|
||||
|
||||
Pass your own regexes to extend the limited matching rules.
|
||||
|
||||
```js
|
||||
// Example:
|
||||
var uaString = 'ownbrowser/1.3';
|
||||
var ownBrowser = [[/(ownbrowser)\/((\d+)?[\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION, UAParser.BROWSER.MAJOR]];
|
||||
var parser = new UAParser(uaString, {browser: ownBrowser});
|
||||
console.log(parser.getBrowser()); // {name: "ownbrowser", major: "1", version: "1.3"}
|
||||
```
|
||||
|
||||
### Using node.js
|
||||
|
||||
```sh
|
||||
@@ -188,10 +174,18 @@ $ npm install ua-parser-js
|
||||
```
|
||||
|
||||
```js
|
||||
var UAParser = require('ua-parser-js');
|
||||
var parser = new UAParser();
|
||||
var ua = request.headers['user-agent']; // user-agent header from an HTTP request
|
||||
console.log(parser.setUA(ua).getResult());
|
||||
var http = require('http');
|
||||
var parser = require('ua-parser-js');
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
// get user-agent header
|
||||
var ua = parser(req.headers['user-agent']);
|
||||
// write the result as response
|
||||
res.end(JSON.stringify(ua, null, ' '));
|
||||
})
|
||||
.listen(1337, '127.0.0.1');
|
||||
|
||||
console.log('Server running at http://127.0.0.1:1337/');
|
||||
```
|
||||
|
||||
### Using requirejs
|
||||
@@ -209,12 +203,6 @@ require(['ua-parser'], function(UAParser) {
|
||||
$ component install faisalman/ua-parser-js
|
||||
```
|
||||
|
||||
```js
|
||||
var UAParser = require('ua-parser-js');
|
||||
var parser = new UAParser();
|
||||
console.log(parser.getResult());
|
||||
```
|
||||
|
||||
### Using bower
|
||||
|
||||
```sh
|
||||
@@ -250,12 +238,27 @@ console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type:
|
||||
console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
|
||||
```
|
||||
|
||||
### Extending regex patterns
|
||||
|
||||
* `UAParser(uastring[, extensions])`
|
||||
|
||||
Pass your own regexes to extend the limited matching rules.
|
||||
|
||||
```js
|
||||
// Example:
|
||||
var uaString = 'ownbrowser/1.3';
|
||||
var ownBrowser = [[/(ownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]];
|
||||
var parser = new UAParser(uaString, {browser: ownBrowser});
|
||||
console.log(parser.getBrowser()); // {name: "ownbrowser", version: "1.3"}
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
Verify, test, & minify script
|
||||
|
||||
```sh
|
||||
$ npm test
|
||||
$ npm run test
|
||||
$ npm run build
|
||||
```
|
||||
|
||||
Then submit a pull request to https://github.com/faisalman/ua-parser-js under `develop` branch.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* UAParser.js v0.7.7
|
||||
* UAParser.js v0.7.9
|
||||
* Lightweight JavaScript-based User-Agent string parser
|
||||
* https://github.com/faisalman/ua-parser-js
|
||||
*
|
||||
@@ -16,7 +16,7 @@
|
||||
/////////////
|
||||
|
||||
|
||||
var LIBVERSION = '0.7.7',
|
||||
var LIBVERSION = '0.7.9',
|
||||
EMPTY = '',
|
||||
UNKNOWN = '?',
|
||||
FUNC_TYPE = 'function',
|
||||
@@ -249,14 +249,16 @@
|
||||
|
||||
// Webkit/KHTML based
|
||||
/(rekonq)\/([\w\.]+)*/i, // Rekonq
|
||||
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi)\/([\w\.-]+)/i
|
||||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron
|
||||
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium)\/([\w\.-]+)/i
|
||||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt/Iron/Iridium
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(trident).+rv[:\s]([\w\.]+).+like\sgecko/i, // IE11
|
||||
/(Edge)\/((\d+)?[\w\.]+)/i // IE12
|
||||
/(trident).+rv[:\s]([\w\.]+).+like\sgecko/i // IE11
|
||||
], [[NAME, 'IE'], VERSION], [
|
||||
|
||||
/(edge)\/((\d+)?[\w\.]+)/i // Microsoft Edge
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(yabrowser)\/([\w\.]+)/i // Yandex
|
||||
], [[NAME, 'Yandex'], VERSION], [
|
||||
|
||||
@@ -300,6 +302,8 @@
|
||||
// Gecko based
|
||||
/(navigator|netscape)\/([\w\.-]+)/i // Netscape
|
||||
], [[NAME, 'Netscape'], VERSION], [
|
||||
/fxios\/([\w\.-]+)/i // Firefox for iOS
|
||||
], [VERSION, [NAME, 'Firefox']], [
|
||||
/(swiftfox)/i, // Swiftfox
|
||||
/(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,
|
||||
// IceDragon/Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
|
||||
@@ -653,6 +657,9 @@
|
||||
|
||||
engine : [[
|
||||
|
||||
/windows.+\sedge\/([\w\.]+)/i // EdgeHTML
|
||||
], [VERSION, [NAME, 'EdgeHTML']], [
|
||||
|
||||
/(presto)\/([\w\.]+)/i, // Presto
|
||||
/(webkit|trident|netfront|netsurf|amaya|lynx|w3m)\/([\w\.]+)/i, // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m
|
||||
/(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i, // KHTML/Tasman/Links
|
||||
@@ -679,7 +686,7 @@
|
||||
], [[NAME, 'BlackBerry'], VERSION], [
|
||||
/(blackberry)\w*\/?([\w\.]+)*/i, // Blackberry
|
||||
/(tizen)[\/\s]([\w\.]+)/i, // Tizen
|
||||
/(android|webos|palm\os|qnx|bada|rim\stablet\sos|meego|contiki)[\/\s-]?([\w\.]+)*/i,
|
||||
/(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|contiki)[\/\s-]?([\w\.]+)*/i,
|
||||
// Android/WebOS/Palm/QNX/Bada/RIM/MeeGo/Contiki
|
||||
/linux;.+(sailfish);/i // Sailfish OS
|
||||
], [NAME, VERSION], [
|
||||
@@ -860,4 +867,4 @@
|
||||
};
|
||||
}
|
||||
|
||||
})(this);
|
||||
})(typeof window === 'object' ? window : this);
|
||||
|
||||
@@ -690,13 +690,23 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Windows 10 EI",
|
||||
"desc" : "Microsoft Edge",
|
||||
"ua" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "IE",
|
||||
"name" : "Edge",
|
||||
"version" : "12.0",
|
||||
"major" : "12"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Iridium",
|
||||
"ua" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Iridium/43.8 Safari/537.36 Chrome/43.0.2357.132",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "Iridium",
|
||||
"version" : "43.8",
|
||||
"major" : "43"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
[
|
||||
{
|
||||
"desc" : "EdgeHTML",
|
||||
"ua" : "Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 Edge/12.0",
|
||||
"expect" :
|
||||
{
|
||||
"name" : "EdgeHTML",
|
||||
"version" : "12.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "Gecko",
|
||||
"ua" : "Mozilla/5.0 (X11; Linux x86_64; rv:2.0b9pre) Gecko/20110111 Firefox/4.0b9pre",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"title": "UAParser.js",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.7.7",
|
||||
"version": "0.7.9",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
"user-agent",
|
||||
|
||||
Reference in New Issue
Block a user