@@ -2422,7 +2422,7 @@ Returns undefined when the browser is no described in the checkTree
-
Check if any of the given values satifies this.is(anything)
+
Check if any of the given values satisfies this.is(anything)
@@ -2687,7 +2687,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 862d041..36c757e 100644
--- a/docs/bowser.js.html
+++ b/docs/bowser.js.html
@@ -105,7 +105,7 @@ export default Bowser;
diff --git a/docs/global.html b/docs/global.html
index 4310d63..98d163a 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -766,7 +766,7 @@ like "iPhone" or "Kindle Fire HD 7"
diff --git a/docs/index.html b/docs/index.html
index 066ec44..0ec5acb 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -62,9 +62,10 @@
Please, note that this is an alpha version. Check out the 1.x branch for a stable version.
Changes of version 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 ES5 version of files, which
-do not include any polyfills.
+
Use cases
First of all, require the library. This is a UMD Module, so it will work for AMD, Typescript and CommonJS module systems.
+
const Bowser = require("bowser"); // CommonJS
+
+import * as Bowser from "bowser" // Typescript
By default, the exported version is the ES5 transpiled version, which do not include any polyfills.
In case 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.
const browser = bowser.getParser(window.navigator.userAgent);
impression.userTechData = browser.parse();
console.log(impression.userTechData);
+
// outputs
{
browser: {
@@ -115,14 +117,14 @@ const isValidBrowser = browser.satisfies({
// per platform (mobile, desktop or tablet)
mobile: {
- safari: '>9',
+ safari: '>=9',
'android browser': '>3.10'
},
// or in general
- chrome: ">20.1.1432",
+ chrome: "~20.1.1432",
firefox: ">31",
- opera: ">22"
+ opera: ">=22"
// also supports equality operator
chrome: "=20.1.1432", // will match particular build only
@@ -134,8 +136,9 @@ const isValidBrowser = browser.satisfies({
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.
Contributing
If you'd like to contribute a change to bowser, modify the files in src/, then run the following (you'll need node + npm installed):
-
$ npm install
-$ npm test
Adding tests
See the list in test/acceptance/useragentstrings.yml with example user agents and their expected bowser object.
+
$ npm install #build
+$ npm test #run tests
+$ npm run lint #check lint rules
Adding tests
See the list in test/acceptance/useragentstrings.yml with example user agents and their expected bowser object.
Whenever you add support for new browsers or notice a bug / mismatch, please update the list and
check if all tests are still passing.
Similar Projects
@@ -156,7 +159,7 @@ check if all tests are still passing.
diff --git a/docs/parser.js.html b/docs/parser.js.html
index ca103aa..0646f5a 100644
--- a/docs/parser.js.html
+++ b/docs/parser.js.html
@@ -358,8 +358,7 @@ class Parser {
* @return {ParsedResult}
*/
getResult() {
- /* TODO: Make this function pure, return a new object instead of the reference */
- return this.parsedResult;
+ return Object.assign({}, this.parsedResult);
}
/**
@@ -438,7 +437,7 @@ class Parser {
}
compareVersion(version) {
- let expectedResult = 0;
+ let expectedResults = [0];
let comparableVersion = version;
let isLoose = false;
@@ -448,12 +447,19 @@ class Parser {
return void 0;
}
- if (version[0] === '>') {
- expectedResult = 1;
- comparableVersion = version.substr(1);
- } else if (version[0] === '<') {
- expectedResult = -1;
+ if (version[0] === '>' || version[0] === '<') {
comparableVersion = version.substr(1);
+ if (version[1] === '=') {
+ isLoose = true;
+ comparableVersion = version.substr(2);
+ } else {
+ expectedResults = [];
+ }
+ if (version[0] === '>') {
+ expectedResults.push(1);
+ } else {
+ expectedResults.push(-1);
+ }
} else if (version[0] === '=') {
comparableVersion = version.substr(1);
} else if (version[0] === '~') {
@@ -461,7 +467,9 @@ class Parser {
comparableVersion = version.substr(1);
}
- return compareVersions(currentBrowserVersion, comparableVersion, isLoose) === expectedResult;
+ return expectedResults.indexOf(
+ compareVersions(currentBrowserVersion, comparableVersion, isLoose),
+ ) > -1;
}
isOS(osName) {
@@ -483,7 +491,7 @@ class Parser {
}
/**
- * Check if any of the given values satifies this.is(anything)
+ * Check if any of the given values satisfies this.is(anything)
* @param {String[]} anythings
* @returns {Boolean}
*/
@@ -507,7 +515,7 @@ export default Parser;
diff --git a/docs/utils.js.html b/docs/utils.js.html
index 1a044e3..0ae24cb 100644
--- a/docs/utils.js.html
+++ b/docs/utils.js.html
@@ -94,6 +94,50 @@
}
}
+ /**
+ * Get Android version name
+ * 1.5 - Cupcake
+ * 1.6 - Donut
+ * 2.0 - Eclair
+ * 2.1 - Eclair
+ * 2.2 - Froyo
+ * 2.x - Gingerbread
+ * 3.x - Honeycomb
+ * 4.0 - Ice Cream Sandwich
+ * 4.1 - Jelly Bean
+ * 4.4 - KitKat
+ * 5.x - Lollipop
+ * 6.x - Marshmallow
+ * 7.x - Nougat
+ * 8.x - Oreo
+ * 9.x - ?
+ *
+ * @example
+ * getAndroidVersionName("7.0") // 'Nougat'
+ *
+ * @param {string} version
+ * @return {string} versionName
+ */
+ static getAndroidVersionName(version) {
+ const v = version.split('.').splice(0, 2).map(s => parseInt(s, 10) || 0);
+ v.push(0);
+ if (v[0] === 1 && v[1] < 5) return undefined;
+ if (v[0] === 1 && v[1] < 6) return 'Cupcake';
+ if (v[0] === 1 && v[1] >= 6) return 'Donut';
+ if (v[0] === 2 && v[1] < 2) return 'Eclair';
+ if (v[0] === 2 && v[1] === 2) return 'Froyo';
+ if (v[0] === 2 && v[1] > 2) return 'Gingerbread';
+ if (v[0] === 3) return 'Honeycomb';
+ if (v[0] === 4 && v[1] < 1) return 'Ice Cream Sandwich';
+ if (v[0] === 4 && v[1] < 4) return 'Jelly Bean';
+ if (v[0] === 4 && v[1] >= 4) return 'KitKat';
+ if (v[0] === 5) return 'Lollipop';
+ if (v[0] === 6) return 'Marshmallow';
+ if (v[0] === 7) return 'Nougat';
+ if (v[0] === 8) return 'Oreo';
+ return undefined;
+ }
+
/**
* Get version precisions count
*
@@ -203,7 +247,7 @@ module.exports = Utils;
diff --git a/src/parser.js b/src/parser.js
index 673c62a..a296977 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -448,7 +448,7 @@ class Parser {
}
/**
- * Check if any of the given values satifies this.is(anything)
+ * Check if any of the given values satisfies this.is(anything)
* @param {String[]} anythings
* @returns {Boolean}
*/