From 2bc8982b428de4d0856a6756c6e1521810a917c3 Mon Sep 17 00:00:00 2001 From: Denis Demchenko Date: Sat, 18 Aug 2018 14:14:56 +0300 Subject: [PATCH] Regen docs --- docs/Bowser.html | 2 +- docs/Parser.html | 6 +++--- docs/bowser.js.html | 4 ++-- docs/global.html | 2 +- docs/index.html | 16 +++++++++++----- docs/parser.js.html | 9 +++++++-- docs/utils.js.html | 32 ++++++++++++++++++++------------ 7 files changed, 45 insertions(+), 26 deletions(-) diff --git a/docs/Bowser.html b/docs/Bowser.html index dffd5cf..fc09b9d 100644 --- a/docs/Bowser.html +++ b/docs/Bowser.html @@ -559,7 +559,7 @@ bowser.getResult()
diff --git a/docs/Parser.html b/docs/Parser.html index 40bf929..d56ee5c 100644 --- a/docs/Parser.html +++ b/docs/Parser.html @@ -1558,7 +1558,7 @@ like Parser#parseBrowser or Source:
@@ -2376,7 +2376,7 @@ Returns undefined when the browser is no described in the checkTree
Source:
@@ -2679,7 +2679,7 @@ Returns undefined when the browser is no described in the checkTree
diff --git a/docs/bowser.js.html b/docs/bowser.js.html index aad1c8f..4de7f93 100644 --- a/docs/bowser.js.html +++ b/docs/bowser.js.html @@ -65,7 +65,7 @@ class Bowser { * const bowser = new Bowser(window.navigator.userAgent); * bowser.getResult() */ - static getParser(UA, skipParsing=false) { + static getParser(UA, skipParsing = false) { if (typeof UA !== 'string') { throw new Error('UserAgent should be a string'); } @@ -96,7 +96,7 @@ export default Bowser;
diff --git a/docs/global.html b/docs/global.html index 5e2a961..e84f500 100644 --- a/docs/global.html +++ b/docs/global.html @@ -758,7 +758,7 @@ like "iPhone" or "Kindle Fire HD 7" diff --git a/docs/index.html b/docs/index.html index efeb771..d192c10 100644 --- a/docs/index.html +++ b/docs/index.html @@ -59,13 +59,12 @@

Changes of the 2.0 The upcoming 2.0 version has drastically changed API. All available methods can be found in the docs folder from now on and on a webpage soon.

Use cases

First of all, require the library:

-
const bowser = require('bowser');

By default, require('bowser') requires the ES6 version of files, which +

const bowser = require('bowser');

By default, require('bowser') requires the ES5 version of files, which do not include any polyfills.

In case if you don't use your own babel-polyfill you may need to have pre-built bundle with all needed polyfills. So, for you it's suitable to require bowser like this: require('bowser/bundled'). As the result, you get a ES5 version of bowser with babel-polyfill bundled together.

-

If you use bowser for Node.js, you'd better use require('bowser/es5'), -since source files have import statements, which are not compatible with Node.js yet.

+

You may need to use the source files, so they will be available in the package as well.

Browser props detection

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 make it with Bowser:

const browser = bowser.getParser(window.navigator.userAgent);
 
@@ -100,7 +99,7 @@ console.log(impression.userTechData);
   }
 }

Filtering browsers

You could want to filter some particular browsers to provide any special support for them or make any workarounds. It could look like this:

-
const browser = bowser.getParsers(window.navigator.userAgent);
+
const browser = bowser.getParser(window.navigator.userAgent);
 const isValidBrowser = browser.satisfies({
   // declare browsers per OS
   windows: {
@@ -120,6 +119,13 @@ const isValidBrowser = browser.satisfies({
   chrome: ">20.1.1432",
   firefox: ">31",
   opera: ">22"
+
+  // also supports equality operator
+  chrome: "=20.1.1432", // will match particular build only
+
+  // and loose-equality operator
+  chrome: "~20"         // will match any 20.* sub-version
+  chrome: "~20.1"       // will match any 20.1.* sub-version (20.1.19 as well as 20.1.12.42-alpha.1)
 });

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.

More of API and possibilities you will find in the docs folder.

@@ -144,7 +150,7 @@ check if all tests are still passing.


- Documentation generated by JSDoc 3.5.5 on Sun Jul 22 2018 19:42:18 GMT+0300 (EEST) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Sat Aug 18 2018 14:14:47 GMT+0300 (EEST) using the docdash theme.
diff --git a/docs/parser.js.html b/docs/parser.js.html index 863ee8a..491d283 100644 --- a/docs/parser.js.html +++ b/docs/parser.js.html @@ -436,6 +436,7 @@ class Parser { compareVersion(version) { let expectedResult = 0; let comparableVersion = version; + let isLoose = false; if (version[0] === '>') { expectedResult = 1; @@ -445,8 +446,12 @@ class Parser { comparableVersion = version.substr(1); } else if (version[0] === '=') { comparableVersion = version.substr(1); + } else if (version[0] === '~') { + isLoose = true; + comparableVersion = version.substr(1); } - return compareVersions(this.getBrowserVersion(), comparableVersion) === expectedResult; + + return compareVersions(this.getBrowserVersion(), comparableVersion, isLoose) === expectedResult; } isOS(osName) { @@ -490,7 +495,7 @@ export default Parser;
- Documentation generated by JSDoc 3.5.5 on Sun Jul 22 2018 19:42:18 GMT+0300 (EEST) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Sat Aug 18 2018 14:14:47 GMT+0300 (EEST) using the docdash theme.
diff --git a/docs/utils.js.html b/docs/utils.js.html index ac9ba16..5eeb1a0 100644 --- a/docs/utils.js.html +++ b/docs/utils.js.html @@ -107,23 +107,26 @@ * Calculate browser version weight * * @example - * compareVersions(['1.10.2.1', '1.8.2.1.90']) // 1 - * compareVersions(['1.010.2.1', '1.09.2.1.90']); // 1 - * compareVersions(['1.10.2.1', '1.10.2.1']); // 0 - * compareVersions(['1.10.2.1', '1.0800.2']); // -1 + * compareVersions('1.10.2.1', '1.8.2.1.90') // 1 + * compareVersions('1.010.2.1', '1.09.2.1.90'); // 1 + * compareVersions('1.10.2.1', '1.10.2.1'); // 0 + * compareVersions('1.10.2.1', '1.0800.2'); // -1 + * compareVersions('1.10.2.1', '1.10', true); // 0 * * @param {String} versionA versions versions to compare * @param {String} versionB versions versions to compare + * @param {boolean} [isLoose] enable loose comparison * @return {Number} comparison result: -1 when versionA is lower, * 1 when versionA is bigger, 0 when both equal */ /* eslint consistent-return: 1 */ - static compareVersions(versionA, versionB) { + static compareVersions(versionA, versionB, isLoose = false) { // 1) get common precision for both versions, for example for "10.0" and "9" it should be 2 - let precision = Math.max( - Utils.getVersionPrecision(versionA), - Utils.getVersionPrecision(versionB), - ); + const versionAPrecision = Utils.getVersionPrecision(versionA); + const versionBPrecision = Utils.getVersionPrecision(versionB); + + let precision = Math.max(versionAPrecision, versionBPrecision); + let lastPrecision = 0; const chunks = Utils.map([versionA, versionB], (version) => { const delta = precision - Utils.getVersionPrecision(version); @@ -135,14 +138,19 @@ return Utils.map(_version.split('.'), chunk => new Array(20 - chunk.length).join('0') + chunk).reverse(); }); + // adjust precision for loose comparison + if (isLoose) { + lastPrecision = precision - Math.min(versionAPrecision, versionBPrecision); + } + // iterate in reverse order by reversed chunks array precision -= 1; - while (precision >= 0) { + while (precision >= lastPrecision) { // 4) compare: "000000009" > "000000010" = false (but "9" > "10" = true) if (chunks[0][precision] > chunks[1][precision]) { return 1; } else if (chunks[0][precision] === chunks[1][precision]) { - if (precision === 0) { + if (precision === lastPrecision) { // all version chunks are same return 0; } @@ -186,7 +194,7 @@ module.exports = Utils;
- Documentation generated by JSDoc 3.5.5 on Sun Jul 22 2018 19:42:18 GMT+0300 (EEST) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Sat Aug 18 2018 14:14:47 GMT+0300 (EEST) using the docdash theme.