2016-05-06 18:29:22 +00:00
|
|
|
/*!
|
|
|
|
* Bowser - a browser detector
|
2018-06-27 20:04:25 +00:00
|
|
|
* https://github.com/lancedikson/bowser
|
2018-06-27 19:52:43 +00:00
|
|
|
* MIT License | (c) Dustin Diaz 2012-2015
|
2019-07-16 19:19:07 +00:00
|
|
|
* MIT License | (c) Denis Demchenko 2015-2019
|
2016-05-06 18:29:22 +00:00
|
|
|
*/
|
2019-02-14 16:06:14 +00:00
|
|
|
import Parser from './parser.js';
|
2019-12-19 21:50:05 +00:00
|
|
|
import {
|
2019-05-20 07:33:10 +00:00
|
|
|
BROWSER_MAP,
|
|
|
|
ENGINE_MAP,
|
|
|
|
OS_MAP,
|
|
|
|
PLATFORMS_MAP,
|
|
|
|
} from './constants.js';
|
2016-05-06 18:29:22 +00:00
|
|
|
|
2018-06-27 19:52:43 +00:00
|
|
|
/**
|
2018-07-05 19:44:43 +00:00
|
|
|
* Bowser class.
|
|
|
|
* Keep it simple as much as it can be.
|
|
|
|
* It's supposed to work with collections of {@link Parser} instances
|
2018-07-04 19:36:46 +00:00
|
|
|
* rather then solve one-instance problems.
|
|
|
|
* All the one-instance stuff is located in Parser class.
|
2019-07-16 19:19:07 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @classdesc Bowser is a static object, that provides an API to the Parsers
|
|
|
|
* @hideconstructor
|
2018-06-27 19:52:43 +00:00
|
|
|
*/
|
|
|
|
class Bowser {
|
2016-06-16 09:06:15 +00:00
|
|
|
/**
|
2019-07-16 19:19:07 +00:00
|
|
|
* Creates a {@link Parser} instance
|
2018-07-04 19:36:46 +00:00
|
|
|
*
|
2018-07-05 19:44:43 +00:00
|
|
|
* @param {String} UA UserAgent string
|
2019-07-16 19:19:07 +00:00
|
|
|
* @param {Boolean} [skipParsing=false] Will make the Parser postpone parsing until you ask it
|
|
|
|
* explicitly. Same as `skipParsing` for {@link Parser}.
|
2018-07-04 19:36:46 +00:00
|
|
|
* @returns {Parser}
|
2019-07-17 10:47:18 +00:00
|
|
|
* @throws {Error} when UA is not a String
|
2016-06-16 10:41:21 +00:00
|
|
|
*
|
2016-06-16 09:06:15 +00:00
|
|
|
* @example
|
2018-10-19 17:32:59 +00:00
|
|
|
* const parser = Bowser.getParser(window.navigator.userAgent);
|
|
|
|
* const result = parser.getResult();
|
2016-06-16 09:06:15 +00:00
|
|
|
*/
|
2018-08-02 18:24:08 +00:00
|
|
|
static getParser(UA, skipParsing = false) {
|
2018-06-30 16:21:09 +00:00
|
|
|
if (typeof UA !== 'string') {
|
2019-07-17 10:47:18 +00:00
|
|
|
throw new Error('UserAgent should be a string');
|
2016-06-16 10:38:25 +00:00
|
|
|
}
|
2018-06-30 14:25:47 +00:00
|
|
|
return new Parser(UA, skipParsing);
|
2016-06-16 10:38:25 +00:00
|
|
|
}
|
|
|
|
|
2018-07-05 19:44:43 +00:00
|
|
|
/**
|
|
|
|
* Creates a {@link Parser} instance and runs {@link Parser.getResult} immediately
|
|
|
|
*
|
|
|
|
* @param UA
|
|
|
|
* @return {ParsedResult}
|
2018-10-19 17:32:59 +00:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* const result = Bowser.parse(window.navigator.userAgent);
|
2018-07-05 19:44:43 +00:00
|
|
|
*/
|
2018-06-27 19:52:43 +00:00
|
|
|
static parse(UA) {
|
2018-07-05 19:58:14 +00:00
|
|
|
return (new Parser(UA)).getResult();
|
2016-06-16 09:06:15 +00:00
|
|
|
}
|
2011-04-27 22:14:35 +00:00
|
|
|
|
2019-07-16 19:00:28 +00:00
|
|
|
static get BROWSER_MAP() {
|
|
|
|
return BROWSER_MAP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get ENGINE_MAP() {
|
|
|
|
return ENGINE_MAP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get OS_MAP() {
|
|
|
|
return OS_MAP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static get PLATFORMS_MAP() {
|
|
|
|
return PLATFORMS_MAP;
|
|
|
|
}
|
|
|
|
}
|
2019-05-20 07:33:10 +00:00
|
|
|
|
2018-06-27 19:52:43 +00:00
|
|
|
export default Bowser;
|