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

2804 lines
29 KiB
HTML
Raw Normal View History

2018-09-09 12:08:48 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Parser - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
2019-03-06 12:31:37 +00:00
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Bowser.html">Bowser</a><ul class='methods'><li data-type='method'><a href="Bowser.html#.getParser">getParser</a></li><li data-type='method'><a href="Bowser.html#.parse">parse</a></li></ul></li><li><a href="Parser.html">Parser</a><ul class='methods'><li data-type='method'><a href="Parser.html#getBrowser">getBrowser</a></li><li data-type='method'><a href="Parser.html#getBrowserName">getBrowserName</a></li><li data-type='method'><a href="Parser.html#getBrowserVersion">getBrowserVersion</a></li><li data-type='method'><a href="Parser.html#getEngine">getEngine</a></li><li data-type='method'><a href="Parser.html#getEngineName">getEngineName</a></li><li data-type='method'><a href="Parser.html#getOS">getOS</a></li><li data-type='method'><a href="Parser.html#getOSName">getOSName</a></li><li data-type='method'><a href="Parser.html#getOSVersion">getOSVersion</a></li><li data-type='method'><a href="Parser.html#getPlatform">getPlatform</a></li><li data-type='method'><a href="Parser.html#getPlatformType">getPlatformType</a></li><li data-type='method'><a href="Parser.html#getResult">getResult</a></li><li data-type='method'><a href="Parser.html#getUA">getUA</a></li><li data-type='method'><a href="Parser.html#is">is</a></li><li data-type='method'><a href="Parser.html#parse">parse</a></li><li data-type='method'><a href="Parser.html#parseBrowser">parseBrowser</a></li><li data-type='method'><a href="Parser.html#parseEngine">parseEngine</a></li><li data-type='method'><a href="Parser.html#parseOS">parseOS</a></li><li data-type='method'><a href="Parser.html#parsePlatform">parsePlatform</a></li><li data-type='method'><a href="Parser.html#satisfies">satisfies</a></li><li data-type='method'><a href="Parser.html#some">some</a></li><li data-type='method'><a href="Parser.html#test">test</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#getAndroidVersionName">getAndroidVersionName</a></li><li><a href="global.html#getFirstMatch">getFirstMatch</a></li><li><a href="global.html#getSecondMatch">getSecondMatch</a></li><li><a href="global.html#getVersionPrecision">getVersionPrecision</a></li><li><a href="global.html#map">map</a></li><li><a href="global.html#matchAndReturnConst">matchAndReturnConst</a></li></ul>
2018-09-09 12:08:48 +00:00
</nav>
<div id="main">
<h1 class="page-title">Parser</h1>
<section>
<header>
<h2>
Parser
</h2>
<div class="class-description"><p>The main class that arranges the whole parsing process.</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="Parser"><span class="type-signature"></span>new Parser<span class="signature">(UA, skipParsing<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line10">line 10</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Create instance of Parser</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>UA</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>User-Agent string</p></td>
</tr>
<tr>
<td class="name"><code>skipParsing</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
<code>false</code>
</td>
2018-07-05 19:44:43 +00:00
<td class="description last"><p>parser can skip parsing in purpose of performance
improvements if you need to make a more particular parsing
2018-09-09 12:08:48 +00:00
like <a href="Parser.html#parseBrowser">Parser#parseBrowser</a> or <a href="Parser.html#parsePlatform">Parser#parsePlatform</a></p></td>
</tr>
</tbody>
</table>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="getBrowser"><span class="type-signature"></span>getBrowser<span class="signature">()</span><span class="type-signature"> &rarr; {Object}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line110">line 110</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get parsed browser object</p>
</div>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="getBrowserName"><span class="type-signature"></span>getBrowserName<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line124">line 124</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get browser's name</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>Browser's name or an empty string</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
<h4 class="name" id="getBrowserVersion"><span class="type-signature"></span>getBrowserVersion<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line138">line 138</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get browser's version</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>version of browser</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
<h4 class="name" id="getEngine"><span class="type-signature"></span>getEngine<span class="signature">()</span><span class="type-signature"> &rarr; {Object}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line267">line 267</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get parsed engine</p>
</div>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
2019-02-14 03:41:45 +00:00
<h4 class="name" id="getEngineName"><span class="type-signature"></span>getEngineName<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line281">line 281</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get engines's name</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>Engines's name or an empty string</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
2018-09-09 12:08:48 +00:00
<h4 class="name" id="getOS"><span class="type-signature"></span>getOS<span class="signature">()</span><span class="type-signature"> &rarr; {Object}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line153">line 153</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get OS</p>
</div>
<h5>Example</h5>
2018-07-05 19:44:43 +00:00
<pre class="prettyprint"><code>this.getOS();
{
name: 'macOS',
version: '10.11.12'
2018-09-09 12:08:48 +00:00
}</code></pre>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="getOSName"><span class="type-signature"></span>getOSName<span class="signature">(toLowerCase<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {String}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line192">line 192</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get OS name</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>toLowerCase</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>return lower-cased value</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>name of the OS — macOS, Windows, Linux, etc.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
<h4 class="name" id="getOSVersion"><span class="type-signature"></span>getOSVersion<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line206">line 206</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get OS version</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>full version with dots ('10.11.12', '5.6', etc)</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
<h4 class="name" id="getPlatform"><span class="type-signature"></span>getPlatform<span class="signature">()</span><span class="type-signature"> &rarr; {Object}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line214">line 214</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get parsed platform</p>
</div>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="getPlatformType"><span class="type-signature"></span>getPlatformType<span class="signature">(toLowerCase<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {*}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line227">line 227</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get platform name</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>toLowerCase</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
<code>false</code>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
</dd>
</dl>
<h4 class="name" id="getResult"><span class="type-signature"></span>getResult<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="global.html#ParsedResult">ParsedResult</a>}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2019-02-14 03:41:45 +00:00
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line330">line 330</a>
2018-09-09 12:08:48 +00:00
</li></ul></dd>
</dl>
<div class="description">
<p>Get parsed result</p>
</div>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="global.html#ParsedResult">ParsedResult</a></span>
</dd>
</dl>
<h4 class="name" id="getUA"><span class="type-signature"></span>getUA<span class="signature">()</span><span class="type-signature"> &rarr; {String}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line65">line 65</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get UserAgent string of current Parser instance</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>User-Agent String of the current <Parser> object</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
<h4 class="name" id="is"><span class="type-signature"></span>is<span class="signature">(anything)</span><span class="type-signature"> &rarr; {Boolean}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2019-02-14 03:41:45 +00:00
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line463">line 463</a>
2018-09-09 12:08:48 +00:00
</li></ul></dd>
</dl>
<div class="description">
2018-07-05 19:44:43 +00:00
<p>Is anything? Check if the browser is called &quot;anything&quot;,
2018-09-09 12:08:48 +00:00
the OS called &quot;anything&quot; or the platform called &quot;anything&quot;</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>anything</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Boolean</span>
</dd>
</dl>
<h4 class="name" id="parse"><span class="type-signature"></span>parse<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2019-02-14 03:41:45 +00:00
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line317">line 317</a>
2018-09-09 12:08:48 +00:00
</li></ul></dd>
</dl>
<div class="description">
<p>Parse full information about the browser</p>
</div>
<h4 class="name" id="parseBrowser"><span class="type-signature"></span>parseBrowser<span class="signature">()</span><span class="type-signature"> &rarr; {Object}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line82">line 82</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get parsed browser object</p>
</div>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="parseEngine"><span class="type-signature"></span>parseEngine<span class="signature">()</span><span class="type-signature"> &rarr; {Object}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2019-02-14 03:41:45 +00:00
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line292">line 292</a>
2018-09-09 12:08:48 +00:00
</li></ul></dd>
</dl>
<div class="description">
<p>Get parsed platform</p>
</div>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="parseOS"><span class="type-signature"></span>parseOS<span class="signature">()</span><span class="type-signature"> &rarr; {*|Object}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line165">line 165</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Parse OS and save it to this.parsedResult.os</p>
</div>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
|
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="parsePlatform"><span class="type-signature"></span>parsePlatform<span class="signature">()</span><span class="type-signature"> &rarr; {Object}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line241">line 241</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Get parsed platform</p>
</div>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="satisfies"><span class="type-signature"></span>satisfies<span class="signature">(checkTree)</span><span class="type-signature"> &rarr; {Boolean|undefined}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2019-02-14 03:41:45 +00:00
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line352">line 352</a>
2018-09-09 12:08:48 +00:00
</li></ul></dd>
</dl>
<div class="description">
<p>Check if parsed browser matches certain conditions</p>
</div>
<h5>Example</h5>
2018-07-08 09:09:27 +00:00
<pre class="prettyprint"><code>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
2018-09-09 12:08:48 +00:00
if (browser.check({desktop: { chrome: '>118.01.1322' } }))</code></pre>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>checkTree</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
2018-07-08 09:09:27 +00:00
<td class="description last"><p>It's one or two layered object,
which can include a platform or an OS on the first layer
2018-09-09 12:08:48 +00:00
and should have browsers specs on the bottom-laying layer</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
2018-07-08 09:09:27 +00:00
<p>Whether the browser satisfies the set conditions or not.
2018-09-09 12:08:48 +00:00
Returns <code>undefined</code> when the browser is no described in the checkTree object.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Boolean</span>
|
<span class="param-type">undefined</span>
</dd>
</dl>
<h4 class="name" id="some"><span class="type-signature"></span>some<span class="signature">(anythings)</span><span class="type-signature"> &rarr; {Boolean}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
2019-02-14 03:41:45 +00:00
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line472">line 472</a>
2018-09-09 12:08:48 +00:00
</li></ul></dd>
</dl>
<div class="description">
2019-01-19 13:44:08 +00:00
<p>Check if any of the given values satisfies this.is(anything)</p>
2018-09-09 12:08:48 +00:00
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>anythings</code></td>
<td class="type">
<span class="param-type">Array.&lt;String></span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Boolean</span>
</dd>
</dl>
<h4 class="name" id="test"><span class="type-signature"></span>test<span class="signature">(regex)</span><span class="type-signature"> &rarr; {Boolean}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="parser.js.html">parser.js</a>, <a href="parser.js.html#line74">line 74</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Test a UA string for a regexp</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>regex</code></td>
<td class="type">
<span class="param-type">RegExp</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Boolean</span>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
2019-03-06 12:31:37 +00:00
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Mar 06 2019 14:31:23 GMT+0200 (EET) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2018-09-09 12:08:48 +00:00
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
2018-07-05 19:44:43 +00:00
</html>