From b804285d5c8c070f0bdb751eebb932b5a5c0f4d6 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 19 Jan 2019 16:39:05 +0100 Subject: [PATCH 01/10] Removed alpha version reference in the readme --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a9db3c7..02c6f9d 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,12 @@ A browser detector. Because sometimes, there is no other way, and not even good 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. -_Please, note that this is an alpha version. Check out the [1.x](https://github.com/lancedikson/bowser/tree/v1.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. + +The version 2.0 has drastically changed API. All available methods can be found in the `docs` folder from now on and on a webpage soon. + +_For legacy code, check out the [1.x](https://github.com/lancedikson/bowser/tree/v1.x) branch and install it through `npm install bowser@1.9.4`._ + # Use cases From c882d03ad43e437cdeeeb2251a4cb46012fcc2f3 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 19 Jan 2019 16:42:58 +0100 Subject: [PATCH 02/10] Fixed broken indentation for typings --- index.d.ts | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/index.d.ts b/index.d.ts index 78108b9..49e797b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -13,7 +13,7 @@ declare namespace Bowser { * @param {boolean} skipParsing */ - function getParser(UA: string, skipParsing?: boolean): Parser.Parser; + function getParser(UA: string, skipParsing?: boolean): Parser.Parser; /** * Creates a Parser instance and runs Parser.getResult immediately @@ -26,28 +26,28 @@ declare namespace Bowser { declare namespace Parser { class Parser { - constructor(UA: string, skipParsing?: boolean); + constructor(UA: string, skipParsing?: boolean); /** * Get parsed browser object * @return {BrowserDetails} Browser's details */ - getBrowser(): BrowserDetails; + getBrowser(): BrowserDetails; /** * Get browser's name * @return {String} Browser's name or an empty string */ - getBrowserName(): string; + getBrowserName(): string; /** * Get browser's version * @return {String} version of browser */ - getBrowserVersion(): string; + getBrowserVersion(): string; /** * Get OS @@ -60,7 +60,7 @@ declare namespace Parser { * // } */ - getOS(): OSDetails; + getOS(): OSDetails; /** * Get OS name @@ -68,49 +68,49 @@ declare namespace Parser { * @return {String} name of the OS — macOS, Windows, Linux, etc. */ - getOSName(toLowerCase?: boolean): string; + getOSName(toLowerCase?: boolean): string; /** * Get OS version * @return {String} full version with dots ('10.11.12', '5.6', etc) */ - getOSVersion(): string; + getOSVersion(): string; /** * Get parsed platform * @returns {PlatformDetails} */ - getPlatform(): PlatformDetails; + getPlatform(): PlatformDetails; /** * Get platform name * @param {boolean} toLowerCase */ - getPlatformType(toLowerCase?: boolean): string; + getPlatformType(toLowerCase?: boolean): string; /** * Get parsed engine * @returns {EngineDetails} */ - getEngine(): EngineDetails; + getEngine(): EngineDetails; /** * Get parsed result * @return {ParsedResult} */ - getResult(): ParsedResult; + getResult(): ParsedResult; /** * Get UserAgent string of current Parser instance * @return {String} User-Agent String of the current object */ - getUA(): string; + getUA(): string; /** * Is anything? Check if the browser is called "anything", @@ -119,41 +119,41 @@ declare namespace Parser { * @returns {Boolean} */ - is(anything: any): boolean; + is(anything: any): boolean; /** * Parse full information about the browser */ - parse(): void; + parse(): void; /** * Get parsed browser object * @returns {BrowserDetails} */ - parseBrowser(): BrowserDetails; + parseBrowser(): BrowserDetails; /** * Get parsed engine * @returns {EngineDetails} */ - parseEngine(): EngineDetails; + parseEngine(): EngineDetails; /** * Parse OS and save it to this.parsedResult.os * @returns {OSDetails} */ - parseOS(): OSDetails; + parseOS(): OSDetails; /** * Get parsed platform * @returns {PlatformDetails} */ - parsePlatform(): PlatformDetails; + parsePlatform(): PlatformDetails; /** * Check if parsed browser matches certain conditions @@ -174,7 +174,7 @@ declare namespace Parser { * if (browser.check({desktop: { chrome: '>118.01.1322' } })) */ - satisfies(checkTree: checkTree): boolean | undefined; + satisfies(checkTree: checkTree): boolean | undefined; /** * Check if any of the given values satifies `.is(anything)` @@ -182,7 +182,7 @@ declare namespace Parser { * @returns {boolean} true if at least one condition is satisfied, false otherwise. */ - some(anythings: string[]): boolean | undefined; + some(anythings: string[]): boolean | undefined; /** * Test a UA string for a regexp @@ -191,34 +191,34 @@ declare namespace Parser { */ test(regex: RegExp): boolean; - } + } interface ParsedResult { browser: BrowserDetails; os: OSDetails; platform: PlatformDetails; engine: EngineDetails; - } + } interface Details { name?: string; version?: string; - } + } interface OSDetails extends Details { versionName?: string; - } + } interface PlatformDetails { type?: string; vendor?: string; model?: string; - } + } type BrowserDetails = Details; type EngineDetails = Details; - interface checkTree { + interface checkTree { [key: string]: any; } } From 7fcca781f07c42eb6b936795bc1469783e81a064 Mon Sep 17 00:00:00 2001 From: JBallin Date: Mon, 21 Jan 2019 11:14:22 -0800 Subject: [PATCH 03/10] Capitalize imported Bowser object --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a9db3c7..6c7b457 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ You may need to use the source files, so they will be available in the package a 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: ```javascript -const browser = bowser.getParser(window.navigator.userAgent); +const browser = Bowser.getParser(window.navigator.userAgent); console.log(`The current browser name is "${browser.getBrowserName()}"`); // The current browser name is "Internet Explorer" @@ -52,7 +52,7 @@ or ```javascript const impression = new Impression(); -const browser = bowser.getParser(window.navigator.userAgent); +const browser = Bowser.getParser(window.navigator.userAgent); const browserInfo = browser.getBrowser(); impression.brName = browserInfo.name; impression.brVer = browserInfo.version; @@ -61,7 +61,7 @@ impression.brVer = browserInfo.version; or ```javascript -const browser = bowser.getParser(window.navigator.userAgent); +const browser = Bowser.getParser(window.navigator.userAgent); impression.userTechData = browser.parse(); console.log(impression.userTechData); @@ -93,7 +93,7 @@ You could want to filter some particular browsers to provide any special support It could look like this: ```javascript -const browser = bowser.getParser(window.navigator.userAgent); +const browser = Bowser.getParser(window.navigator.userAgent); const isValidBrowser = browser.satisfies({ // declare browsers per OS windows: { From e87ce75599768866414e5f06cfbcb8177c7991e9 Mon Sep 17 00:00:00 2001 From: JBallin Date: Mon, 21 Jan 2019 11:21:33 -0800 Subject: [PATCH 04/10] Move contribution instructions from README to CONTRIBUTING --- CONTRIBUTING.md | 24 ++++++++++++++++++++++++ README.md | 19 ------------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6a4640e..0d4930e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,31 @@ # Contributing +We're always open to pull requests or code reviews. Everyone can become a permanent contributor. Just ping @lancedikson in the issues or on Twitter ❤️ + +## Branches + The project runs Git-flow, where the `master` branch is the development one and `production` is the production one. In a nutshell, if you're about to propose a new feature with adding some totally new functionality to `bowser`, it's better to branch from `master` and make a PR pointing back to `master` as well. + If it's a small hotfix, fix a typo in the docs or you've added support for a new browser/OS/platform/etc, then it's better to branch from `production` and make a PR pointing back to `production`. + Following these simple rules will help to maintain the repo a lot! Thanks ❤️ + +## 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. + +## Testing + +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): + +``` sh +$ npm install +$ npm run build #build +$ npm test #run tests +$ npm run lint #check lint rules +``` diff --git a/README.md b/README.md index a9db3c7..88f5b36 100644 --- a/README.md +++ b/README.md @@ -128,25 +128,6 @@ Thus, you can define OS or platform specific rules and they will have more prior More of API and possibilities you will find in the `docs` folder. -# Contributing - -We're always open to pull requests or code reviews. Everyone can become a permanent contributor. Just ping @lancedikson in the issues or on Twitter ❤️ - -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): - -``` sh -$ npm install -$ npm run build #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 * [Kong](https://github.com/BigBadBleuCheese/Kong) - A C# port of Bowser. From 86f8f63e502fc2d5cbe3c1502672681db72623c8 Mon Sep 17 00:00:00 2001 From: JBallin Date: Mon, 21 Jan 2019 11:28:11 -0800 Subject: [PATCH 05/10] Improve CONTRIBUTING.md --- CONTRIBUTING.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0d4930e..2652439 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,24 +4,24 @@ We're always open to pull requests or code reviews. Everyone can become a perman ## Branches -The project runs Git-flow, where the `master` branch is the development one and `production` is the production one. +The project runs Git-flow, where the `master` branch is for development and `production` is for production. -In a nutshell, if you're about to propose a new feature with adding some totally new functionality to `bowser`, it's better to branch from `master` and make a PR pointing back to `master` as well. +In a nutshell, if you are proposing a new feature that adds totally new functionality to `bowser`, it's better to branch from `master` and make a PR pointing back to `master` as well. -If it's a small hotfix, fix a typo in the docs or you've added support for a new browser/OS/platform/etc, then it's better to branch from `production` and make a PR pointing back to `production`. +If it's a small hot-fix, an improvement to the docs, or added support for a new browser/OS/platform/etc, then it's better to branch from `production` and make a PR pointing back to `production`. -Following these simple rules will help to maintain the repo a lot! Thanks ❤️ +Following these simple rules will really help maintain the repo! Thanks ❤️ ## Adding Tests -See the list in `test/acceptance/useragentstrings.yml` with example user agents and their expected bowser object. +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. ## Testing -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): +If you'd like to contribute a change to `bowser`, modify the files in `src/`, and run the following (you'll need `node` + `npm` installed): ``` sh $ npm install From fed702a14889a7d50846294f31e8d0401a052893 Mon Sep 17 00:00:00 2001 From: JBallin Date: Tue, 22 Jan 2019 09:08:50 -0800 Subject: [PATCH 06/10] Fix 'TypeScript' capitalization and add missing semicolon --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a9db3c7..3bfada9 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,12 @@ The upcoming 2.0 version has drastically changed API. All available methods can # Use cases -First of all, require the library. This is a UMD Module, so it will work for AMD, Typescript and CommonJS module systems. +First of all, require the library. This is a UMD Module, so it will work for AMD, TypeScript and CommonJS module systems. ```javascript const Bowser = require("bowser"); // CommonJS -import * as Bowser from "bowser" // Typescript +import * as Bowser from "bowser"; // TypeScript ``` By default, the exported version is the *ES5 transpiled version*, which **do not** include any polyfills. From 73be17508d1805652944b185c93c6bce532b9dfc Mon Sep 17 00:00:00 2001 From: JBallin Date: Tue, 22 Jan 2019 09:09:48 -0800 Subject: [PATCH 07/10] Add ES6 import example --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3bfada9..2161d66 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,14 @@ The upcoming 2.0 version has drastically changed API. All available methods can # Use cases -First of all, require the library. This is a UMD Module, so it will work for AMD, TypeScript and CommonJS module systems. +First of all, require the library. This is a UMD Module, so it will work for AMD, TypeScript, ES6, and CommonJS module systems. ```javascript const Bowser = require("bowser"); // CommonJS import * as Bowser from "bowser"; // TypeScript + +import Bowser from "bowser"; // ES6 (and TypeScript with --esModuleInterop enabled) ``` By default, the exported version is the *ES5 transpiled version*, which **do not** include any polyfills. From 65988ac79cc597b9486e3047f913a90a6720c6d3 Mon Sep 17 00:00:00 2001 From: Frank Faubert Date: Thu, 24 Jan 2019 08:37:59 -0500 Subject: [PATCH 08/10] Add operating system detection for Chrome OS --- src/parser-os.js | 10 ++++++++++ test/acceptance/useragentstrings.yml | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/parser-os.js b/src/parser-os.js index 446a7cb..06c5c72 100644 --- a/src/parser-os.js +++ b/src/parser-os.js @@ -144,4 +144,14 @@ export default [ }; }, }, + + /* Chrome OS */ + { + test: [/CrOS/], + describe() { + return { + name: 'Chrome OS', + }; + }, + }, ]; diff --git a/test/acceptance/useragentstrings.yml b/test/acceptance/useragentstrings.yml index 0ee3ce4..f7a1cbe 100644 --- a/test/acceptance/useragentstrings.yml +++ b/test/acceptance/useragentstrings.yml @@ -174,7 +174,8 @@ browser: name: "Chrome" version: "29.0.1547.57" - os: {} + os: + name: "Chrome OS" platform: {} engine: name: "Blink" From 83e8f61109909bffcc3323226243ed07e11c9da4 Mon Sep 17 00:00:00 2001 From: Frank Faubert Date: Thu, 24 Jan 2019 09:04:37 -0500 Subject: [PATCH 09/10] Add getEngineName and isEngine API calls --- src/parser.js | 17 +++++++++++++++++ test/unit/parser.js | 15 +++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/parser.js b/src/parser.js index a296977..4893ef0 100644 --- a/src/parser.js +++ b/src/parser.js @@ -272,6 +272,19 @@ class Parser { return this.parseEngine(); } + /** + * Get engines's name + * @return {String} Engines's name or an empty string + * + * @public + */ + getEngineName(toLowerCase) { + if (toLowerCase) { + return String(this.getEngine().name).toLowerCase() || ''; + } + return this.getEngine().name || ''; + } + /** * Get parsed platform * @return {{}} @@ -437,6 +450,10 @@ class Parser { return this.getPlatformType(true) === String(platformType).toLowerCase(); } + isEngine(engineName) { + return this.getEngineName(true) === String(engineName).toLowerCase(); + } + /** * Is anything? Check if the browser is called "anything", * the OS called "anything" or the platform called "anything" diff --git a/test/unit/parser.js b/test/unit/parser.js index 309aa72..17a020f 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -53,6 +53,21 @@ test('Parser.getOSVersion returns a correct result', (t) => { t.is(parser.getOSVersion(), '10.12.4'); }); +test('Parser.parseEngine is being called when getEngine() called', (t) => { + const spy = sinon.spy(parser, 'parseEngine'); + parser.getEngine(); + t.truthy(spy.called); + parser.parseEngine.restore(); +}); + +test('Parser.getEngineName gives a name of the engine', (t) => { + t.is(parser.getEngineName(), 'Blink'); +}); + +test('Parser.getEngineName gives a lower-cased name of the engine', (t) => { + t.is(parser.getEngineName(true), 'blink'); +}); + test('Skip parsing shouldn\'t parse', (t) => { t.deepEqual((new Parser(UA, true)).getResult(), {}); }); From a8900397b2f92ab2f5b2d44aaf320eeeb818d50a Mon Sep 17 00:00:00 2001 From: Denis Demchenko Date: Thu, 24 Jan 2019 23:06:07 +0200 Subject: [PATCH 10/10] Bump version, write changelog --- CHANGELOG.md | 5 +++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ac7494..2317396 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Bowser Changelog +### 2.1.0 (January 24, 2019) +- [ADD] Add new `Parser.getEngineName()` method (#288) +- [ADD] Add detection of ChromeOS (#287) +- [FIX] Fix README + ### 2.0.0 (January 19, 2019) - [ADD] Support a non strict equality in `Parser.satisfies()` (#275) - [ADD] Add Android versions names (#276) diff --git a/package-lock.json b/package-lock.json index 10930d6..123cecc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bowser", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index c5be526..ec4b562 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bowser", - "version": "2.0.0", + "version": "2.1.0", "description": "Lightweight browser detector", "keywords": [ "browser",