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

170 lines
8.6 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>Home - 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>
<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#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><a href="global.html">Global</a></h3>
</nav>
<div id="main">
<section class="readme">
<article><h2>Bowser</h2><p>A browser detector. Because sometimes, there is no other way, and not even good modern browsers always provide good feature detection mechanisms.</p>
2018-09-09 12:08:48 +00:00
<p><a href="https://travis-ci.org/lancedikson/bowser/"><img src="https://travis-ci.org/lancedikson/bowser.svg?branch=master" alt="Build Status"></a> <a href="https://greenkeeper.io/"><img src="https://badges.greenkeeper.io/lancedikson/bowser.svg" alt="Greenkeeper badge"></a></p>
2018-07-08 09:09:27 +00:00
<h1>Contents</h1><ul>
2018-07-22 16:38:52 +00:00
<li><a href="#overview">Overview</a></li>
<li><a href="#use-cases">Use cases</a></li>
<li><a href="#advanced-usage">Advanced usage</a></li>
<li><a href="#contributing">How can I help?</a></li>
2018-07-08 09:09:27 +00:00
</ul>
2018-07-22 16:38:52 +00:00
<h1>Overview</h1><p>The library is made to help to detect what browser your user has and gives you a convenient API to filter the users somehow depending on their browsers.</p>
<p><em>Please, note that this is an alpha version. Check out the <a href="https://github.com/lancedikson/bowser/tree/v1.x">1.x</a> branch for a stable version.</em></p>
<p><strong>Changes of version 2.0</strong>
2018-07-22 16:38:52 +00:00
The upcoming 2.0 version has drastically changed API. All available methods can be found in the <code>docs</code> folder from now on and on a webpage soon.</p>
2019-01-19 13:44:08 +00:00
<h1>Use cases</h1><p>First of all, require the library. This is a UMD Module, so it will work for AMD, Typescript and CommonJS module systems.</p>
<pre class="prettyprint source lang-javascript"><code>const Bowser = require(&quot;bowser&quot;); // CommonJS
import * as Bowser from &quot;bowser&quot; // Typescript</code></pre><p>By default, the exported version is the <em>ES5 transpiled version</em>, which <strong>do not</strong> include any polyfills.</p>
<p>In case you don't use your own <code>babel-polyfill</code> you may need to have pre-built bundle with all needed polyfills.
2018-07-22 16:38:52 +00:00
So, for you it's suitable to require bowser like this: <code>require('bowser/bundled')</code>.
As the result, you get a ES5 version of bowser with <code>babel-polyfill</code> bundled together.</p>
2018-08-18 11:14:56 +00:00
<p>You may need to use the source files, so they will be available in the package as well.</p>
<h2>Browser props detection</h2><p>Often we need to pick users' browser properties such as the name, the version, the rendering engine and so on. Here is an example how to do it with Bowser:</p>
2018-07-22 16:38:52 +00:00
<pre class="prettyprint source lang-javascript"><code>const browser = bowser.getParser(window.navigator.userAgent);
2018-07-08 09:09:27 +00:00
console.log(`The current browser name is &quot;${browser.getBrowserName()}&quot;`);
// The current browser name is &quot;Internet Explorer&quot;</code></pre><p>or</p>
2018-07-22 16:38:52 +00:00
<pre class="prettyprint source lang-javascript"><code>const impression = new Impression();
2018-07-08 09:09:27 +00:00
2018-07-22 16:38:52 +00:00
const browser = bowser.getParser(window.navigator.userAgent);
2018-07-08 09:09:27 +00:00
const browserInfo = browser.getBrowser();
impression.brName = browserInfo.name;
impression.brVer = browserInfo.version;</code></pre><p>or</p>
2018-07-22 16:38:52 +00:00
<pre class="prettyprint source lang-javascript"><code>const browser = bowser.getParser(window.navigator.userAgent);
2018-07-08 09:09:27 +00:00
impression.userTechData = browser.parse();
console.log(impression.userTechData);
2019-01-19 13:44:08 +00:00
2018-07-08 09:09:27 +00:00
// outputs
{
browser: {
name: &quot;Internet Explorer&quot;
version: &quot;11.0&quot;
},
os: {
name: &quot;Windows&quot;
version: &quot;NT 6.3&quot;
versionName: &quot;8.1&quot;
},
platform: {
type: &quot;desktop&quot;
},
engine: {
name: &quot;Trident&quot;
version: &quot;7.0&quot;
}
2018-07-22 16:38:52 +00:00
}</code></pre><h2>Filtering browsers</h2><p>You could want to filter some particular browsers to provide any special support for them or make any workarounds.
2018-07-08 09:09:27 +00:00
It could look like this:</p>
2018-08-18 11:14:56 +00:00
<pre class="prettyprint source lang-javascript"><code>const browser = bowser.getParser(window.navigator.userAgent);
2018-07-22 16:38:52 +00:00
const isValidBrowser = browser.satisfies({
2018-07-08 09:09:27 +00:00
// declare browsers per OS
windows: {
&quot;internet explorer&quot;: &quot;>10&quot;,
},
macos: {
safari: &quot;>10.1&quot;
},
// per platform (mobile, desktop or tablet)
mobile: {
2019-01-19 13:44:08 +00:00
safari: '>=9',
2018-07-08 09:09:27 +00:00
'android browser': '>3.10'
},
// or in general
2019-01-19 13:44:08 +00:00
chrome: &quot;~20.1.1432&quot;,
2018-07-08 09:09:27 +00:00
firefox: &quot;>31&quot;,
2019-01-19 13:44:08 +00:00
opera: &quot;>=22&quot;
2018-08-18 11:14:56 +00:00
// also supports equality operator
chrome: &quot;=20.1.1432&quot;, // will match particular build only
// and loose-equality operator
chrome: &quot;~20&quot; // will match any 20.* sub-version
chrome: &quot;~20.1&quot; // will match any 20.1.* sub-version (20.1.19 as well as 20.1.12.42-alpha.1)
2018-07-22 16:38:52 +00:00
});</code></pre><p>Settings for any particular OS or platform has more priority and redefines settings of standalone browsers.
Thus, you can define OS or platform specific rules and they will have more priority in the end.</p>
<p>More of API and possibilities you will find in the <code>docs</code> folder.</p>
<h1>Contributing</h1><p>If you'd like to contribute a change to bowser, modify the files in <code>src/</code>, then run the following (you'll need node + npm installed):</p>
2019-01-19 13:44:08 +00:00
<pre class="prettyprint source lang-sh"><code>$ npm install #build
$ npm test #run tests
$ npm run lint #check lint rules</code></pre><h3>Adding tests</h3><p>See the list in <code>test/acceptance/useragentstrings.yml</code> with example user agents and their expected bowser object.</p>
2018-07-08 09:09:27 +00:00
<p>Whenever you add support for new browsers or notice a bug / mismatch, please update the list and
check if all tests are still passing.</p>
<h3>Similar Projects</h3><ul>
<li><a href="https://github.com/BigBadBleuCheese/Kong">Kong</a> - A C# port of Bowser.</li>
</ul>
2018-09-09 12:08:48 +00:00
<h3>License</h3><p>Licensed as MIT. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.</p></article>
</section>
</div>
<br class="clear">
<footer>
2019-01-19 13:44:08 +00:00
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sat Jan 19 2019 15:43:45 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>