Skip to content

Commit

Permalink
Merge branch 'hotfix/2.2.1' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
lancedikson committed Apr 12, 2019
2 parents 1d66cb9 + 51d8b0f commit d3046bf
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Bowser Changelog

### 2.2.1 (April 12, 2019)
- [ADD] Add an alias for Samsung Internet
- [FIX] Fix browser name detection for browsers without an alias (#313)

### 2.2.0 (April 7, 2019)
- [ADD] Add short aliases for browser names (#295)
- [FIX] Fix Yandex Browser version detection (#308)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bowser",
"version": "2.2.0",
"version": "2.2.1",
"description": "Lightweight browser detector",
"keywords": [
"browser",
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const BROWSER_ALIASES_MAP = {
QupZilla: 'qupzilla',
Safari: 'safari',
Sailfish: 'sailfish',
'Samsung Internet for Android': 'samsung_internet',
SeaMonkey: 'seamonkey',
Sleipnir: 'sleipnir',
Swing: 'swing',
Expand Down
19 changes: 13 additions & 6 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,11 @@ class Parser {
*
* @example
* const browser = new Bowser(UA);
* if (browser.check({chrome: '>118.01.1322' }))
* if (browser.satisfies({chrome: '>118.01.1322' }))
* // or with os
* if (browser.check({windows: { chrome: '>118.01.1322' } }))
* if (browser.satisfies({windows: { chrome: '>118.01.1322' } }))
* // or with platforms
* if (browser.check({desktop: { chrome: '>118.01.1322' } }))
* if (browser.satisfies({desktop: { chrome: '>118.01.1322' } }))
*/
satisfies(checkTree) {
const platformsAndOSes = {};
Expand Down Expand Up @@ -402,12 +402,19 @@ class Parser {
return undefined;
}

isBrowser(browserName, loosely = false) {
/**
* Check if the browser name equals the passed string
* @param browserName The string to compare with the browser name
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
* @returns {boolean}
*/
isBrowser(browserName, includingAlias = false) {
const defaultBrowserName = this.getBrowserName();
const possibleNames = [defaultBrowserName.toLowerCase()];
const alias = Utils.getBrowserAlias(defaultBrowserName);

if (loosely) {
possibleNames.push(Utils.getBrowserAlias(defaultBrowserName).toLowerCase());
if (includingAlias && typeof alias !== 'undefined') {
possibleNames.push(alias.toLowerCase());
}

return possibleNames.indexOf(browserName.toLowerCase()) !== -1;
Expand Down
8 changes: 8 additions & 0 deletions test/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const parser = new Parser(UA, true);
const EDGE_UA = 'Mozilla/5.0 (Linux; Android 8.0; Pixel XL Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.0 Mobile Safari/537.36 EdgA/41.1.35.1';
const edgeParser = new Parser(EDGE_UA, true);

const FOCUS_UA = 'Mozilla/5.0 (Linux; Android 7.1.1) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Focus/1.2.1 Chrome/59.0.3071.125';
const focusParser = new Parser(FOCUS_UA, true);

test('constructor', (t) => {
t.truthy(parser instanceof Parser);
});
Expand Down Expand Up @@ -184,3 +187,8 @@ test('Parser.isBrowser should pass when loosely checking', (t) => {
t.is(edgeParser.isBrowser('edge', true), true);
t.is(edgeParser.isBrowser('Edge', true), true);
});

test('Parser.isBrowser should pass for non-aliased browsers', (t) => {
t.is(focusParser.isBrowser('Focus', true), true);
t.is(focusParser.isBrowser('Focus', false), true);
});

0 comments on commit d3046bf

Please sign in to comment.