Constructor
new Parser(UA, skipParsingopt)
Create instance of Parser
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
UA |
String | User-Agent string |
||
skipParsing |
Boolean |
<optional> |
false
|
parser can skip parsing in purpose of performance improvements if you need to make a more particular parsing like Parser#parseBrowser or Parser#parsePlatform |
Methods
getBrowser() → {Object}
Get parsed browser object
Returns:
- Type
- Object
getBrowserName() → {String}
Get browser's name
Returns:
Browser's name or an empty string
- Type
- String
getBrowserVersion() → {String}
Get browser's version
Returns:
version of browser
- Type
- String
getEngine() → {Object}
Get parsed engine
Returns:
- Type
- Object
getOS() → {Object}
Get OS
Example
this.getOS();
{
name: 'macOS',
version: '10.11.12'
}
Returns:
- Type
- Object
getOSName(toLowerCaseopt) → {String}
Get OS name
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
toLowerCase |
Boolean |
<optional> |
return lower-cased value |
Returns:
name of the OS — macOS, Windows, Linux, etc.
- Type
- String
getOSVersion() → {String}
Get OS version
Returns:
full version with dots ('10.11.12', '5.6', etc)
- Type
- String
getPlatform() → {Object}
Get parsed platform
Returns:
- Type
- Object
getPlatformType(toLowerCaseopt) → {*}
Get platform name
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
toLowerCase |
Boolean |
<optional> |
false
|
Returns:
- Type
- *
getResult() → {ParsedResult}
Get parsed result
Returns:
- Type
- ParsedResult
getUA() → {String}
Get UserAgent string of current Parser instance
Returns:
User-Agent String of the current
- Type
- String
is(anything) → {Boolean}
Is anything? Check if the browser is called "anything", the OS called "anything" or the platform called "anything"
Parameters:
Name | Type | Description |
---|---|---|
anything |
String |
Returns:
- Type
- Boolean
parse()
Parse full information about the browser
parseBrowser() → {Object}
Get parsed browser object
Returns:
- Type
- Object
parseEngine() → {Object}
Get parsed platform
Returns:
- Type
- Object
parseOS() → {*|Object}
Parse OS and save it to this.parsedResult.os
Returns:
- Type
- * | Object
parsePlatform() → {Object}
Get parsed platform
Returns:
- Type
- Object
satisfies(checkTree) → {Boolean|undefined}
Check if parsed browser matches certain conditions
Example
const browser = new Bowser(UA);
if (browser.check({chrome: '>118.01.1322' }))
// or with os
if (browser.check({windows: { chrome: '>118.01.1322' } }))
// or with platforms
if (browser.check({desktop: { chrome: '>118.01.1322' } }))
Parameters:
Name | Type | Description |
---|---|---|
checkTree |
Object | It's one or two layered object, which can include a platform or an OS on the first layer and should have browsers specs on the bottom-laying layer |
Returns:
Whether the browser satisfies the set conditions or not.
Returns undefined
when the browser is no described in the checkTree object.
- Type
- Boolean | undefined
some(anythings) → {Boolean}
Check if any of the given values satifies this.is(anything)
Parameters:
Name | Type | Description |
---|---|---|
anythings |
Array.<String> |
Returns:
- Type
- Boolean
test(regex) → {Boolean}
Test a UA string for a regexp
Parameters:
Name | Type | Description |
---|---|---|
regex |
RegExp |
Returns:
- Type
- Boolean