mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-16 07:02:16 +03:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bf1c732c7 | ||
|
|
97f3368ef0 | ||
|
|
b86860e850 | ||
|
|
157af1e2f2 | ||
|
|
b4cfe1b624 | ||
|
|
95fea1cb26 | ||
|
|
30648cef1d | ||
|
|
10c978eca5 | ||
|
|
fbd2c6853c | ||
|
|
29d5e43342 | ||
|
|
051aa5d284 | ||
|
|
191fed9127 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ua-parser-js",
|
"name": "ua-parser-js",
|
||||||
"version": "0.7.30",
|
"version": "1.0.2",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Faisal Salman <f@faisalman.com>"
|
"Faisal Salman <f@faisalman.com>"
|
||||||
],
|
],
|
||||||
|
|||||||
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
4
dist/ua-parser.pack.js
vendored
4
dist/ua-parser.pack.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
|||||||
Package.describe({
|
Package.describe({
|
||||||
name: 'faisalman:ua-parser-js',
|
name: 'faisalman:ua-parser-js',
|
||||||
version: '0.7.30',
|
version: '1.0.2',
|
||||||
summary: 'Lightweight JavaScript-based user-agent string parser',
|
summary: 'Lightweight JavaScript-based user-agent string parser',
|
||||||
git: 'https://github.com/faisalman/ua-parser-js.git',
|
git: 'https://github.com/faisalman/ua-parser-js.git',
|
||||||
documentation: 'readme.md'
|
documentation: 'readme.md'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"title": "UAParser.js",
|
"title": "UAParser.js",
|
||||||
"name": "ua-parser-js",
|
"name": "ua-parser-js",
|
||||||
"version": "0.7.30",
|
"version": "1.0.2",
|
||||||
"author": "Faisal Salman <f@faisalman.com> (http://faisalman.com)",
|
"author": "Faisal Salman <f@faisalman.com> (http://faisalman.com)",
|
||||||
"description": "Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data. Supports browser & node.js environment",
|
"description": "Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data. Supports browser & node.js environment",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -156,10 +156,12 @@
|
|||||||
],
|
],
|
||||||
"regs": [
|
"regs": [
|
||||||
"^((?:\\$|(\\s*\\*\\s*@)|(\\s*(?:var|,)?\\s+))(?:LIBVERSION|version)[\\s\\:='\"]+)([0-9]+(?:\\.[0-9]+){2,2})",
|
"^((?:\\$|(\\s*\\*\\s*@)|(\\s*(?:var|,)?\\s+))(?:LIBVERSION|version)[\\s\\:='\"]+)([0-9]+(?:\\.[0-9]+){2,2})",
|
||||||
"^(\\s?\\*.*v)([0-9]+(?:\\.[0-9]+){2,2})"
|
"^(\\/?\\s?\\*.*v)([0-9]+(?:\\.[0-9]+){2,2})"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/parser": "7.15.8",
|
||||||
|
"@babel/traverse": "7.15.4",
|
||||||
"jshint": "~2.12.0",
|
"jshint": "~2.12.0",
|
||||||
"mocha": "~8.2.0",
|
"mocha": "~8.2.0",
|
||||||
"requirejs": "^2.3.2",
|
"requirejs": "^2.3.2",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
/* UAParser.js v0.7.28
|
/* UAParser.js v1.0.2
|
||||||
Copyright © 2012-2021 Faisal Salman <f@faisalman.com>
|
Copyright © 2012-2021 Faisal Salman <f@faisalman.com>
|
||||||
MIT License *//*
|
MIT License *//*
|
||||||
Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data.
|
Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data.
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
/////////////
|
/////////////
|
||||||
|
|
||||||
|
|
||||||
var LIBVERSION = '0.7.30',
|
var LIBVERSION = '1.0.2',
|
||||||
EMPTY = '',
|
EMPTY = '',
|
||||||
UNKNOWN = '?',
|
UNKNOWN = '?',
|
||||||
FUNC_TYPE = 'function',
|
FUNC_TYPE = 'function',
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
},
|
},
|
||||||
enumerize = function (arr) {
|
enumerize = function (arr) {
|
||||||
var enums = {};
|
var enums = {};
|
||||||
for (var i in arr) {
|
for (var i=0; i<arr.length; i++) {
|
||||||
enums[arr[i].toUpperCase()] = arr[i];
|
enums[arr[i].toUpperCase()] = arr[i];
|
||||||
}
|
}
|
||||||
return enums;
|
return enums;
|
||||||
@@ -123,7 +123,7 @@
|
|||||||
q = props[p];
|
q = props[p];
|
||||||
// check if given property is actually array
|
// check if given property is actually array
|
||||||
if (typeof q === OBJ_TYPE && q.length > 0) {
|
if (typeof q === OBJ_TYPE && q.length > 0) {
|
||||||
if (q.length == 2) {
|
if (q.length === 2) {
|
||||||
if (typeof q[1] == FUNC_TYPE) {
|
if (typeof q[1] == FUNC_TYPE) {
|
||||||
// assign modified match
|
// assign modified match
|
||||||
this[q[0]] = q[1].call(this, match);
|
this[q[0]] = q[1].call(this, match);
|
||||||
@@ -131,7 +131,7 @@
|
|||||||
// assign given value, ignore regex match
|
// assign given value, ignore regex match
|
||||||
this[q[0]] = q[1];
|
this[q[0]] = q[1];
|
||||||
}
|
}
|
||||||
} else if (q.length == 3) {
|
} else if (q.length === 3) {
|
||||||
// check whether function or regex
|
// check whether function or regex
|
||||||
if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
|
if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
|
||||||
// call function (usually string mapper)
|
// call function (usually string mapper)
|
||||||
@@ -140,7 +140,7 @@
|
|||||||
// sanitize match using given regex
|
// sanitize match using given regex
|
||||||
this[q[0]] = match ? match.replace(q[1], q[2]) : undefined;
|
this[q[0]] = match ? match.replace(q[1], q[2]) : undefined;
|
||||||
}
|
}
|
||||||
} else if (q.length == 4) {
|
} else if (q.length === 4) {
|
||||||
this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined;
|
this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -404,7 +404,7 @@
|
|||||||
|
|
||||||
// OPPO
|
// OPPO
|
||||||
/; (\w+) bui.+ oppo/i,
|
/; (\w+) bui.+ oppo/i,
|
||||||
/\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007)\b/i
|
/\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007|a101op)\b/i
|
||||||
], [MODEL, [VENDOR, 'OPPO'], [TYPE, MOBILE]], [
|
], [MODEL, [VENDOR, 'OPPO'], [TYPE, MOBILE]], [
|
||||||
|
|
||||||
// Vivo
|
// Vivo
|
||||||
|
|||||||
@@ -1242,6 +1242,15 @@
|
|||||||
"type": "mobile"
|
"type": "mobile"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"desc": "OPPO Reno5 A",
|
||||||
|
"ua": "Mozilla/5.0 (Linux; Android 11; A101OP) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Mobile Safari/537.36",
|
||||||
|
"expect": {
|
||||||
|
"vendor": "OPPO",
|
||||||
|
"model": "A101OP",
|
||||||
|
"type": "mobile"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"desc": "OPPO Find X",
|
"desc": "OPPO Find X",
|
||||||
"ua": "Mozilla/5.0 (Linux; Android 8.1; PAFM00 Build/OPM1.171019.026) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36",
|
"ua": "Mozilla/5.0 (Linux; Android 8.1; PAFM00 Build/OPM1.171019.026) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36",
|
||||||
|
|||||||
21
test/test.js
21
test/test.js
@@ -2,6 +2,8 @@ var fs = require('fs');
|
|||||||
var safe = require('safe-regex');
|
var safe = require('safe-regex');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var requirejs = require('requirejs');
|
var requirejs = require('requirejs');
|
||||||
|
var parseJS = require('@babel/parser').parse;
|
||||||
|
var traverse = require('@babel/traverse').default;
|
||||||
var UAParser = require('./../src/ua-parser');
|
var UAParser = require('./../src/ua-parser');
|
||||||
var browsers = require('./browser-test.json');
|
var browsers = require('./browser-test.json');
|
||||||
var cpus = require('./cpu-test.json');
|
var cpus = require('./cpu-test.json');
|
||||||
@@ -137,12 +139,19 @@ describe('Testing regexes', function () {
|
|||||||
|
|
||||||
var regexes;
|
var regexes;
|
||||||
|
|
||||||
// todo: use AST-based instead of grep
|
before('Read main js file', function () {
|
||||||
before('Read main js file', function (done) {
|
var code = fs.readFileSync('src/ua-parser.js', 'utf8').toString();
|
||||||
fs.readFile('src/ua-parser.js', 'utf8', function (err, data) {
|
var ast = parseJS(code, { sourceType: "script" });
|
||||||
regexes = data.match(/(\/.+\/[ig]+)(?=[,\s\n])/g);
|
regexes = [];
|
||||||
done();
|
traverse(ast, {
|
||||||
|
RegExpLiteral: (path) => {
|
||||||
|
regexes.push(path.node.pattern);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (regexes.length === 0) {
|
||||||
|
throw new Error("Regexes cannot be empty!");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Begin testing', function () {
|
describe('Begin testing', function () {
|
||||||
@@ -156,4 +165,4 @@ describe('Testing regexes', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user