mirror of
https://github.com/lancedikson/bowser
synced 2026-03-02 03:40:27 +00:00
Continue writing
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
const getFirstMatch = require('./utils').getFirstMatch;
|
||||
import {
|
||||
getFirstMatch
|
||||
} from './utils';
|
||||
|
||||
const commonVersionIdentifier = /version\/(\d+(\.\d+)?)/i;
|
||||
|
||||
@@ -179,7 +181,7 @@ const browsersList = [
|
||||
{
|
||||
test: [/silk/i],
|
||||
detect(ua) {
|
||||
const version = getFirstMatch(/silk\/(\d+(\.\d+)?)/i);
|
||||
const version = getFirstMatch(/silk\/(\d+(\.\d+)?)/i, ua);
|
||||
return {
|
||||
name: 'Amazon Silk',
|
||||
version
|
||||
@@ -189,7 +191,7 @@ const browsersList = [
|
||||
{
|
||||
test: [/phantom/i],
|
||||
detect(ua) {
|
||||
const version = /phantomjs\/(\d+(\.\d+)?)/i;
|
||||
const version = getFirstMatch(/phantomjs\/(\d+(\.\d+)?)/i, ua);
|
||||
|
||||
return {
|
||||
name: 'PhantomJS',
|
||||
@@ -200,7 +202,7 @@ const browsersList = [
|
||||
{
|
||||
test: [/slimerjs/i],
|
||||
detect(ua) {
|
||||
const version = /slimerjs\/(\d+(\.\d+)?)/i;
|
||||
const version = getFirstMatch(/slimerjs\/(\d+(\.\d+)?)/i, ua);
|
||||
|
||||
return {
|
||||
name: 'SlimerJS',
|
||||
@@ -211,27 +213,85 @@ const browsersList = [
|
||||
{
|
||||
test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
|
||||
detect(ua) {
|
||||
const version = /phantomjs\/(\d+(\.\d+)?)/i;
|
||||
const version = commonVersionIdentifier || getFirstMatch(/blackberry[\d]+\/(\d+(\.\d+)?)/i, ua);
|
||||
|
||||
return {
|
||||
name: 'PhantomJS',
|
||||
name: 'BlackBerry',
|
||||
version
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: [/phantom/i],
|
||||
test: [/(web|hpw)os/i],
|
||||
detect(ua) {
|
||||
const version = /phantomjs\/(\d+(\.\d+)?)/i;
|
||||
const version = commonVersionIdentifier || getFirstMatch(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i, ua);
|
||||
|
||||
return {
|
||||
name: 'PhantomJS',
|
||||
name: 'WebOS Browser',
|
||||
version
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: [/phantom/i],
|
||||
test: [/bada/i],
|
||||
detect(ua) {
|
||||
const version = getFirstMatch(/dolfin\/(\d+(\.\d+)?)/i, ua);
|
||||
|
||||
return {
|
||||
name: 'Bada',
|
||||
version
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: [/tizen/i],
|
||||
detect(ua) {
|
||||
const version = getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i, ua) || commonVersionIdentifier;
|
||||
|
||||
return {
|
||||
name: 'Tizen',
|
||||
version
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: [/qupzilla/i],
|
||||
detect(ua) {
|
||||
const version = getFirstMatch(/(?:qupzilla)[\s\/](\d+(?:\.\d+)+)/i, ua) || commonVersionIdentifier;
|
||||
|
||||
return {
|
||||
name: 'QupZilla',
|
||||
version
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: [/chromium/i],
|
||||
detect(ua) {
|
||||
const version = getFirstMatch(/(?:chromium)[\s\/](\d+(?:\.\d+)?)/i, ua) || commonVersionIdentifier;
|
||||
|
||||
return {
|
||||
name: 'Chromium',
|
||||
version
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: [/chrome|crios|crmo/i],
|
||||
detect(ua) {
|
||||
const version = getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i, ua);
|
||||
|
||||
return {
|
||||
name: 'Chrome',
|
||||
version
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test(parser) {
|
||||
const UA = parser.getUA();
|
||||
return UA.test(/^((?!like android).)*$/i);
|
||||
},
|
||||
detect(ua) {
|
||||
const version = /phantomjs\/(\d+(\.\d+)?)/i;
|
||||
|
||||
@@ -254,4 +314,4 @@ const browsersList = [
|
||||
},
|
||||
];
|
||||
|
||||
module.exports = browsersList;
|
||||
export default browsersList;
|
||||
|
||||
@@ -1,19 +1,62 @@
|
||||
var browsers = require('./parser-browsers');
|
||||
import browsersList from './parser-browsers';
|
||||
|
||||
class Parser {
|
||||
/**
|
||||
* Create instance of Parser
|
||||
* @param UA
|
||||
* @throw
|
||||
* @constructor
|
||||
*/
|
||||
constructor(UA) {
|
||||
this._ua = UA;
|
||||
this.result = {};
|
||||
}
|
||||
|
||||
parseBrowser() {
|
||||
if (this.result.browser) {
|
||||
return this.result.browser;
|
||||
if (UA === void(0) || UA === null || UA === '') {
|
||||
throw new Error("UserAgent parameter can't be empty");
|
||||
}
|
||||
|
||||
const browser = browsers.find((browser) => {
|
||||
return browser.test.some((result, item) => { item.test(this._ua)});
|
||||
this._ua = UA;
|
||||
this.parsedResult = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get UserAgent string of current Parser instance
|
||||
* @return {String}
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
getUA() {
|
||||
return this._ua;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parsed browser object
|
||||
* @return {Object}
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
parseBrowser() {
|
||||
if (this.parsedResult.browser) {
|
||||
return this.parsedResult.browser;
|
||||
}
|
||||
|
||||
this.parsedResult.browser = {};
|
||||
|
||||
const browser = browsersList.find((browser) => {
|
||||
return browser.test(this);
|
||||
});
|
||||
|
||||
if (browser) {
|
||||
this.parsedResult.browser = browser.parse(this.getUA());
|
||||
}
|
||||
|
||||
return this.parsedResult.browser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a UA string for a regexp
|
||||
* @param {RegExp} regex
|
||||
* @return {Boolean}
|
||||
*/
|
||||
test(regex) {
|
||||
return regex.test(this._ua);
|
||||
}
|
||||
|
||||
parseBrowserName() {}
|
||||
@@ -25,4 +68,4 @@ class Parser {
|
||||
parseFullInfo(){}
|
||||
}
|
||||
|
||||
module.exports = Parser;
|
||||
export default Parser;
|
||||
|
||||
@@ -13,6 +13,7 @@ class Utils {
|
||||
/**
|
||||
* Get second matched item for a string
|
||||
* @param regexp
|
||||
* @param {String} ua
|
||||
* @return {Array|{index: number, input: string}|*|boolean|string}
|
||||
*/
|
||||
static getSecondMatch(regexp, ua) {
|
||||
|
||||
Reference in New Issue
Block a user