1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00

Merge tag '2.2.1'

no message
This commit is contained in:
Denis Demchenko 2019-04-12 21:46:51 +03:00
commit 16a4936f47
6 changed files with 28 additions and 8 deletions

View File

@ -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)

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "bowser",
"version": "2.2.0",
"version": "2.2.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "bowser",
"version": "2.2.0",
"version": "2.2.1",
"description": "Lightweight browser detector",
"keywords": [
"browser",

View File

@ -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',

View File

@ -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;

View File

@ -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);
});