diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a30be6..b141de1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/package-lock.json b/package-lock.json index fc5383e..f9cfa56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bowser", - "version": "2.2.0", + "version": "2.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9db9c71..8167cc0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bowser", - "version": "2.2.0", + "version": "2.2.1", "description": "Lightweight browser detector", "keywords": [ "browser", diff --git a/src/constants.js b/src/constants.js index d0e084c..dfae9ee 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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', diff --git a/src/parser.js b/src/parser.js index 88706a8..1470de8 100644 --- a/src/parser.js +++ b/src/parser.js @@ -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 = {}; @@ -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; diff --git a/test/unit/parser.js b/test/unit/parser.js index 10ec0d4..fbe9ae4 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -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); }); @@ -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); +});