1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00

Add eslint support

This commit is contained in:
Denis Demchenko 2017-12-20 23:29:06 +02:00
parent b1170af9d8
commit ad2589f699
11 changed files with 1110 additions and 183 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
src/bowser.js

6
.eslintrc.yml Normal file
View File

@ -0,0 +1,6 @@
extends: airbnb-base
rules:
no-underscore-dangle: 0
no-void: 0
plugins:
- ava

924
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,11 @@
"babel-cli": "^6.26.0", "babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1", "babel-preset-env": "^1.6.1",
"babel-register": "^6.26.0", "babel-register": "^6.26.0",
"eslint": "^4.13.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-ava": "^4.4.0",
"eslint-plugin-import": "^2.8.0",
"husky": "^0.14.3",
"sinon": "^2.4.1", "sinon": "^2.4.1",
"testem": "^1.18.4", "testem": "^1.18.4",
"yamljs": "^0.3.0" "yamljs": "^0.3.0"
@ -42,6 +47,7 @@
"test": "test" "test": "test"
}, },
"scripts": { "scripts": {
"lint": "./node_modules/.bin/eslint ./src --fix",
"testem": "testem", "testem": "testem",
"test": "./node_modules/.bin/ava" "test": "./node_modules/.bin/ava"
}, },

View File

@ -50,7 +50,7 @@ class Bowser {
* @param {Object} range * @param {Object} range
* @returns {Boolean} * @returns {Boolean}
*/ */
static notInRange(range) {} // static notInRange(range) {}
// static filter(UACollection, range) {} // static filter(UACollection, range) {}

View File

@ -25,7 +25,7 @@
import { import {
getFirstMatch, getFirstMatch,
getSecondMatch getSecondMatch,
} from './utils'; } from './utils';
const commonVersionIdentifier = /version\/(\d+(\.?_?\d+)+)/i; const commonVersionIdentifier = /version\/(\d+(\.?_?\d+)+)/i;
@ -36,16 +36,16 @@ const browsersList = [
test: [/opera/i], test: [/opera/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Opera' name: 'Opera',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:opera)[\s\/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
/* Opera > 13.0 */ /* Opera > 13.0 */
@ -53,157 +53,157 @@ const browsersList = [
test: [/opr|opios/i], test: [/opr|opios/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Opera' name: 'Opera',
}; };
const version = getFirstMatch(/(?:opr|opios)[\s\/](\S+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); const version = getFirstMatch(/(?:opr|opios)[\s/](\S+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/SamsungBrowser/i], test: [/SamsungBrowser/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Samsung Internet for Android' name: 'Samsung Internet for Android',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:SamsungBrowser)[\s\/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/coast/i], test: [/coast/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Opera Coast' name: 'Opera Coast',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:coast)[\s\/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/yabrowser/i], test: [/yabrowser/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Yandex Browser' name: 'Yandex Browser',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:yabrowser)[\s\/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/ucbrowser/i], test: [/ucbrowser/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'UC Browser' name: 'UC Browser',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:ucbrowser)[\s\/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/mxios/i], test: [/mxios/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Maxthon' name: 'Maxthon',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:mxios)[\s\/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:mxios)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/epiphany/i], test: [/epiphany/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Epiphany' name: 'Epiphany',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:epiphany)[\s\/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/puffin/i], test: [/puffin/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Puffin' name: 'Puffin',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:puffin)[\s\/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/sleipnir/i], test: [/sleipnir/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Sleipnir' name: 'Sleipnir',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:sleipnir)[\s\/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/k-meleon/i], test: [/k-meleon/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'K-Meleon' name: 'K-Meleon',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:k-meleon)[\s\/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/msie|trident/i], test: [/msie|trident/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Internet Explorer' name: 'Internet Explorer',
}; };
const version = getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i, ua);
@ -212,13 +212,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/edg([ea]|ios)/i], test: [/edg([ea]|ios)/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Microsoft Edge' name: 'Microsoft Edge',
}; };
const version = getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i, ua); const version = getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i, ua);
@ -228,13 +228,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/vivaldi/i], test: [/vivaldi/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Vivaldi' name: 'Vivaldi',
}; };
const version = getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i, ua);
@ -243,13 +243,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/seamonkey/i], test: [/seamonkey/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'SeaMonkey' name: 'SeaMonkey',
}; };
const version = getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i, ua);
@ -258,13 +258,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/sailfish/i], test: [/sailfish/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Sailfish' name: 'Sailfish',
}; };
const version = getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i, ua); const version = getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i, ua);
@ -274,13 +274,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/silk/i], test: [/silk/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Amazon Silk' name: 'Amazon Silk',
}; };
const version = getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i, ua);
@ -289,13 +289,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/phantom/i], test: [/phantom/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'PhantomJS' name: 'PhantomJS',
}; };
const version = getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i, ua);
@ -304,13 +304,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/slimerjs/i], test: [/slimerjs/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'SlimerJS' name: 'SlimerJS',
}; };
const version = getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i, ua);
@ -319,13 +319,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/blackberry|\bbb\d+/i, /rim\stablet/i], test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'BlackBerry' name: 'BlackBerry',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i, ua);
@ -334,13 +334,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/(web|hpw)os/i], test: [/(web|hpw)os/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'WebOS Browser' name: 'WebOS Browser',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/w(?:eb)?osbrowser\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/w(?:eb)?osbrowser\/(\d+(\.?_?\d+)+)/i, ua);
@ -349,13 +349,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/bada/i], test: [/bada/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Bada' name: 'Bada',
}; };
const version = getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i, ua);
@ -364,13 +364,13 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/tizen/i], test: [/tizen/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Tizen' name: 'Tizen',
}; };
const version = getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); const version = getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua);
@ -379,58 +379,58 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
{ {
test: [/qupzilla/i], test: [/qupzilla/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'QupZilla' name: 'QupZilla',
}; };
const version = getFirstMatch(/(?:qupzilla)[\s\/](\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); const version = getFirstMatch(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/firefox|iceweasel|fxios/i], test: [/firefox|iceweasel|fxios/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Firefox' name: 'Firefox',
}; };
const version = getFirstMatch(/(?:firefox|iceweasel|fxios)[ \/](\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/chromium/i], test: [/chromium/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Chromium' name: 'Chromium',
}; };
const version = getFirstMatch(/(?:chromium)[\s\/](\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); const version = getFirstMatch(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua);
if (version) { if (version) {
browser.version = version; browser.version = version;
} }
return browser; return browser;
} },
}, },
{ {
test: [/chrome|crios|crmo/i], test: [/chrome|crios|crmo/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Chrome' name: 'Chrome',
}; };
const version = getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i, ua);
@ -439,7 +439,7 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
/* Android Browser */ /* Android Browser */
@ -451,7 +451,7 @@ const browsersList = [
}, },
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Android Browser' name: 'Android Browser',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua); const version = getFirstMatch(commonVersionIdentifier, ua);
@ -460,7 +460,7 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
/* Safari */ /* Safari */
@ -468,7 +468,7 @@ const browsersList = [
test: [/safari|applewebkit/i], test: [/safari|applewebkit/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Safari' name: 'Safari',
}; };
const version = getFirstMatch(commonVersionIdentifier, ua); const version = getFirstMatch(commonVersionIdentifier, ua);
@ -477,7 +477,7 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
/* Googlebot */ /* Googlebot */
@ -485,7 +485,7 @@ const browsersList = [
test: [/googlebot/i], test: [/googlebot/i],
describe(ua) { describe(ua) {
const browser = { const browser = {
name: 'Googlebot' name: 'Googlebot',
}; };
const version = getFirstMatch(/googlebot\/(\d+(\.\d+))/i, ua) || getFirstMatch(commonVersionIdentifier, ua); const version = getFirstMatch(/googlebot\/(\d+(\.\d+))/i, ua) || getFirstMatch(commonVersionIdentifier, ua);
@ -494,7 +494,7 @@ const browsersList = [
} }
return browser; return browser;
} },
}, },
/* Something else */ /* Something else */
@ -503,10 +503,10 @@ const browsersList = [
describe(ua) { describe(ua) {
return { return {
name: getFirstMatch(/^(.*)\/(.*) /, ua), name: getFirstMatch(/^(.*)\/(.*) /, ua),
version: getSecondMatch(/^(.*)\/(.*) /, ua) version: getSecondMatch(/^(.*)\/(.*) /, ua),
}; };
} },
} },
]; ];
export default browsersList; export default browsersList;

View File

@ -1,5 +1,5 @@
import { import {
getFirstMatch getFirstMatch,
} from './utils'; } from './utils';
/* /*
@ -15,9 +15,9 @@ export default [
const version = getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i, ua);
return { return {
name: 'EdgeHTML', name: 'EdgeHTML',
version version,
}; };
} },
}, },
/* Trident */ /* Trident */
@ -25,7 +25,7 @@ export default [
test: [/trident/i], test: [/trident/i],
describe(ua) { describe(ua) {
const engine = { const engine = {
name: 'Trident' name: 'Trident',
}; };
const version = getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i, ua);
@ -35,7 +35,7 @@ export default [
} }
return engine; return engine;
} },
}, },
/* Presto */ /* Presto */
@ -45,7 +45,7 @@ export default [
}, },
describe(ua) { describe(ua) {
const engine = { const engine = {
name: 'Presto' name: 'Presto',
}; };
const version = getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i, ua);
@ -55,7 +55,7 @@ export default [
} }
return engine; return engine;
} },
}, },
/* Gecko */ /* Gecko */
@ -67,7 +67,7 @@ export default [
}, },
describe(ua) { describe(ua) {
const engine = { const engine = {
name: 'Gecko' name: 'Gecko',
}; };
const version = getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i, ua);
@ -77,7 +77,7 @@ export default [
} }
return engine; return engine;
} },
}, },
/* Blink */ /* Blink */
@ -85,9 +85,9 @@ export default [
test: [/(apple)?webkit\/537\.36/i], test: [/(apple)?webkit\/537\.36/i],
describe() { describe() {
return { return {
name: 'Blink' name: 'Blink',
}; };
} },
}, },
/* WebKit */ /* WebKit */
@ -95,7 +95,7 @@ export default [
test: [/(apple)?webkit/i], test: [/(apple)?webkit/i],
describe(ua) { describe(ua) {
const engine = { const engine = {
name: 'WebKit' name: 'WebKit',
}; };
const version = getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i, ua); const version = getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i, ua);
@ -105,6 +105,6 @@ export default [
} }
return engine; return engine;
} },
} },
]; ];

View File

@ -1,5 +1,5 @@
import { import {
getFirstMatch getFirstMatch,
} from './utils'; } from './utils';
function getWindowsVersionName(version) { function getWindowsVersionName(version) {
@ -26,9 +26,9 @@ export default [
const version = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i, ua); const version = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i, ua);
return { return {
name: 'Windows Phone', name: 'Windows Phone',
version version,
} };
} },
}, },
/* Windows */ /* Windows */
@ -41,9 +41,9 @@ export default [
return { return {
name: 'Windows', name: 'Windows',
version, version,
versionName versionName,
}; };
} },
}, },
/* macOS */ /* macOS */
@ -53,9 +53,9 @@ export default [
const version = getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, '.'); const version = getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, '.');
return { return {
name: 'macOS', name: 'macOS',
version version,
}; };
} },
}, },
/* iOS */ /* iOS */
@ -66,9 +66,9 @@ export default [
return { return {
name: 'iOS', name: 'iOS',
version version,
}; };
} },
}, },
/* Android */ /* Android */
@ -79,12 +79,12 @@ export default [
return notLikeAndroid && butAndroid; return notLikeAndroid && butAndroid;
}, },
describe(ua) { describe(ua) {
const version = getFirstMatch(/android[ \/-](\d+(\.\d+)*)/i, ua); const version = getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, ua);
return { return {
name: 'Android', name: 'Android',
version version,
}; };
} },
}, },
/* WebOS */ /* WebOS */
@ -94,9 +94,9 @@ export default [
const version = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i, ua); const version = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i, ua);
return { return {
name: 'WebOS', name: 'WebOS',
version version,
}; };
} },
}, },
/* BlackBerry */ /* BlackBerry */
@ -109,9 +109,9 @@ export default [
return { return {
name: 'BlackBerry', name: 'BlackBerry',
version version,
}; };
} },
}, },
/* Bada */ /* Bada */
@ -122,22 +122,22 @@ export default [
return { return {
name: 'Bada', name: 'Bada',
version version,
}; };
} },
}, },
/* Tizen */ /* Tizen */
{ {
test: [/tizen/i], test: [/tizen/i],
describe(ua) { describe(ua) {
const version = getFirstMatch(/tizen[\/\s](\d+(\.\d+)*)/i, ua); const version = getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i, ua);
return { return {
name: 'Tizen', name: 'Tizen',
version version,
}; };
} },
}, },
/* Linux */ /* Linux */
@ -145,8 +145,8 @@ export default [
test: [/linux/i], test: [/linux/i],
describe() { describe() {
return { return {
name: 'Linux' name: 'Linux',
} };
} },
} },
] ];

View File

@ -1,11 +1,11 @@
import { import {
getFirstMatch getFirstMatch,
} from './utils'; } from './utils';
const TYPES_LABELS = { const TYPES_LABELS = {
tablet: 'tablet', tablet: 'tablet',
mobile: 'mobile', mobile: 'mobile',
desktop: 'desktop' desktop: 'desktop',
}; };
/* /*
@ -22,7 +22,7 @@ export default [
type: TYPES_LABELS.tablet, type: TYPES_LABELS.tablet,
vendor: 'Nexus', vendor: 'Nexus',
}; };
} },
}, },
/* iPad */ /* iPad */
@ -32,9 +32,9 @@ export default [
return { return {
type: TYPES_LABELS.tablet, type: TYPES_LABELS.tablet,
vendor: 'Apple', vendor: 'Apple',
model: 'iPad' model: 'iPad',
} };
} },
}, },
/* Amazon Kindle Fire */ /* Amazon Kindle Fire */
@ -44,9 +44,9 @@ export default [
return { return {
type: TYPES_LABELS.tablet, type: TYPES_LABELS.tablet,
vendor: 'Amazon', vendor: 'Amazon',
model: 'Kindle Fire HD 7' model: 'Kindle Fire HD 7',
} };
} },
}, },
/* Another Amazon Tablet with Silk */ /* Another Amazon Tablet with Silk */
@ -55,9 +55,9 @@ export default [
describe() { describe() {
return { return {
type: TYPES_LABELS.tablet, type: TYPES_LABELS.tablet,
vendor: 'Amazon' vendor: 'Amazon',
} };
} },
}, },
/* Tablet */ /* Tablet */
@ -65,9 +65,9 @@ export default [
test: [/tablet/i], test: [/tablet/i],
describe() { describe() {
return { return {
type: TYPES_LABELS.tablet type: TYPES_LABELS.tablet,
}; };
} },
}, },
/* iPod/iPhone */ /* iPod/iPhone */
@ -82,9 +82,9 @@ export default [
return { return {
type: TYPES_LABELS.mobile, type: TYPES_LABELS.mobile,
vendor: 'Apple', vendor: 'Apple',
model: model model,
}; };
} },
}, },
/* Nexus Mobile */ /* Nexus Mobile */
@ -93,9 +93,9 @@ export default [
describe() { describe() {
return { return {
type: TYPES_LABELS.mobile, type: TYPES_LABELS.mobile,
vendor: 'Nexus' vendor: 'Nexus',
}; };
} },
}, },
/* Mobile */ /* Mobile */
@ -103,9 +103,9 @@ export default [
test: [/[^-]mobi/i], test: [/[^-]mobi/i],
describe() { describe() {
return { return {
type: TYPES_LABELS.mobile type: TYPES_LABELS.mobile,
}; };
} },
}, },
/* BlackBerry */ /* BlackBerry */
@ -116,9 +116,9 @@ export default [
describe() { describe() {
return { return {
type: TYPES_LABELS.mobile, type: TYPES_LABELS.mobile,
vendor: 'BlackBerry' vendor: 'BlackBerry',
}; };
} },
}, },
/* Bada */ /* Bada */
@ -128,9 +128,9 @@ export default [
}, },
describe() { describe() {
return { return {
type: TYPES_LABELS.mobile type: TYPES_LABELS.mobile,
} };
} },
}, },
/* Windows Phone */ /* Windows Phone */
@ -141,9 +141,9 @@ export default [
describe() { describe() {
return { return {
type: TYPES_LABELS.mobile, type: TYPES_LABELS.mobile,
vendor: 'Microsoft' vendor: 'Microsoft',
} };
} },
}, },
/* Android Tablet */ /* Android Tablet */
@ -154,9 +154,9 @@ export default [
}, },
describe() { describe() {
return { return {
type: TYPES_LABELS.tablet type: TYPES_LABELS.tablet,
} };
} },
}, },
/* Android Mobile */ /* Android Mobile */
@ -166,9 +166,9 @@ export default [
}, },
describe() { describe() {
return { return {
type: TYPES_LABELS.mobile type: TYPES_LABELS.mobile,
} };
} },
}, },
/* desktop */ /* desktop */
@ -179,9 +179,9 @@ export default [
describe() { describe() {
return { return {
type: TYPES_LABELS.desktop, type: TYPES_LABELS.desktop,
vendor: 'Apple' vendor: 'Apple',
}; };
} },
}, },
/* Windows */ /* Windows */
@ -191,9 +191,9 @@ export default [
}, },
describe() { describe() {
return { return {
type: TYPES_LABELS.desktop type: TYPES_LABELS.desktop,
} };
} },
}, },
/* Linux */ /* Linux */
@ -203,8 +203,8 @@ export default [
}, },
describe() { describe() {
return { return {
type: TYPES_LABELS.desktop type: TYPES_LABELS.desktop,
} };
} },
} },
]; ];

View File

@ -47,15 +47,13 @@ class Parser {
_parseBrowser() { _parseBrowser() {
this.parsedResult.browser = {}; this.parsedResult.browser = {};
const browserDescriptor = browserParsersList.find(_browser => { const browserDescriptor = browserParsersList.find((_browser) => {
if (typeof _browser.test === 'function') { if (typeof _browser.test === 'function') {
return _browser.test(this); return _browser.test(this);
} }
if (_browser.test instanceof Array) { if (_browser.test instanceof Array) {
return _browser.test.some((condition) => { return _browser.test.some(condition => this.test(condition));
return this.test(condition);
});
} }
throw new Error("Browser's test function is not valid"); throw new Error("Browser's test function is not valid");
@ -133,15 +131,13 @@ class Parser {
_parseOS() { _parseOS() {
this.parsedResult.os = {}; this.parsedResult.os = {};
const os = osParsersList.find(_os => { const os = osParsersList.find((_os) => {
if (typeof _os.test === 'function') { if (typeof _os.test === 'function') {
return _os.test(this); return _os.test(this);
} }
if (_os.test instanceof Array) { if (_os.test instanceof Array) {
return _os.test.some((condition) => { return _os.test.some(condition => this.test(condition));
return this.test(condition);
});
} }
throw new Error("Browser's test function is not valid"); throw new Error("Browser's test function is not valid");
@ -160,7 +156,7 @@ class Parser {
* @return {String} name of the OS macOS, Windows, Linux, etc. * @return {String} name of the OS macOS, Windows, Linux, etc.
*/ */
getOSName(toLowerCase) { getOSName(toLowerCase) {
const name = this.getOS().name; const { name } = this.getOS();
if (toLowerCase) { if (toLowerCase) {
return String(name).toLowerCase(); return String(name).toLowerCase();
@ -197,15 +193,13 @@ class Parser {
_parsePlatform() { _parsePlatform() {
this.parsedResult.platform = {}; this.parsedResult.platform = {};
const platform = platformParsersList.find(_platform => { const platform = platformParsersList.find((_platform) => {
if (typeof _platform.test === 'function') { if (typeof _platform.test === 'function') {
return _platform.test(this); return _platform.test(this);
} }
if (_platform.test instanceof Array) { if (_platform.test instanceof Array) {
return _platform.test.some((condition) => { return _platform.test.some(condition => this.test(condition));
return this.test(condition);
});
} }
throw new Error("Browser's test function is not valid"); throw new Error("Browser's test function is not valid");
@ -238,15 +232,13 @@ class Parser {
_parseEngine() { _parseEngine() {
this.parsedResult.engine = {}; this.parsedResult.engine = {};
const engine = enginesParsersList.find(_engine => { const engine = enginesParsersList.find((_engine) => {
if (typeof _engine.test === 'function') { if (typeof _engine.test === 'function') {
return _engine.test(this); return _engine.test(this);
} }
if (_engine.test instanceof Array) { if (_engine.test instanceof Array) {
return _engine.test.some((condition) => { return _engine.test.some(condition => this.test(condition));
return this.test(condition);
});
} }
throw new Error("Browser's test function is not valid"); throw new Error("Browser's test function is not valid");