Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constant output so that users can quickly get all types #325

Merged
merged 1 commit into from
May 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/bowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* MIT License | (c) Denis Demchenko 2015-2017
*/
import Parser from './parser.js';
import {
BROWSER_MAP,
ENGINE_MAP,
OS_MAP,
PLATFORMS_MAP,
} from './constants.js';

/**
* Bowser class.
Expand Down Expand Up @@ -47,4 +53,9 @@ class Bowser {
}
}

Bowser.BROWSER_MAP = BROWSER_MAP;
Bowser.ENGINE_MAP = ENGINE_MAP;
Bowser.OS_MAP = OS_MAP;
Bowser.PLATFORMS_MAP = PLATFORMS_MAP;

export default Bowser;
68 changes: 68 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,71 @@ export const BROWSER_ALIASES_MAP = {
WeChat: 'wechat',
'Yandex Browser': 'yandex',
};

export const BROWSER_MAP = {
amazon_silk: 'Amazon Silk',
android: 'Android Browser',
bada: 'Bada',
blackberry: 'BlackBerry',
chrome: 'Chrome',
chromium: 'Chromium',
epiphany: 'Epiphany',
firefox: 'Firefox',
focus: 'Focus',
generic: 'Generic',
googlebot: 'Googlebot',
ie: 'Internet Explorer',
k_meleon: 'K-Meleon',
maxthon: 'Maxthon',
edge: 'Microsoft Edge',
mz: 'MZ Browser',
naver: 'NAVER Whale Browser',
opera: 'Opera',
opera_coast: 'Opera Coast',
phantomjs: 'PhantomJS',
puffin: 'Puffin',
qupzilla: 'QupZilla',
safari: 'Safari',
sailfish: 'Sailfish',
samsung_internet: 'Samsung Internet for Android',
seamonkey: 'SeaMonkey',
sleipnir: 'Sleipnir',
swing: 'Swing',
tizen: 'Tizen',
uc: 'UC Browser',
vivaldi: 'Vivaldi',
webos: 'WebOS Browser',
wechat: 'WeChat',
yandex: 'Yandex Browser',
};

export const PLATFORMS_MAP = {
tablet: 'tablet',
mobile: 'mobile',
desktop: 'desktop',
tv: 'tv',
};

export const OS_MAP = {
WindowsPhone: 'Windows Phone',
Windows: 'Windows',
MacOS: 'macOS',
iOS: 'iOS',
Android: 'Android',
WebOS: 'WebOS',
BlackBerry: 'BlackBerry',
Bada: 'Bada',
Tizen: 'Tizen',
Linux: 'Linux',
ChromeOS: 'Chrome OS',
PlayStation4: 'PlayStation 4',
};

export const ENGINE_MAP = {
EdgeHTML: 'EdgeHTML',
Blink: 'Blink',
Trident: 'Trident',
Presto: 'Presto',
Gecko: 'Gecko',
WebKit: 'WebKit',
};
15 changes: 8 additions & 7 deletions src/parser-engines.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Utils from './utils.js';
import { ENGINE_MAP } from './constants.js';

/*
* More specific goes first
Expand All @@ -15,15 +16,15 @@ export default [
// return blink if it's blink-based one
if (isBlinkBased) {
return {
name: 'Blink',
name: ENGINE_MAP.Blink,
};
}

// otherwise match the version and return EdgeHTML
const version = Utils.getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i, ua);

return {
name: 'EdgeHTML',
name: ENGINE_MAP.EdgeHTML,
version,
};
},
Expand All @@ -34,7 +35,7 @@ export default [
test: [/trident/i],
describe(ua) {
const engine = {
name: 'Trident',
name: ENGINE_MAP.Trident,
};

const version = Utils.getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i, ua);
Expand All @@ -54,7 +55,7 @@ export default [
},
describe(ua) {
const engine = {
name: 'Presto',
name: ENGINE_MAP.Presto,
};

const version = Utils.getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i, ua);
Expand All @@ -76,7 +77,7 @@ export default [
},
describe(ua) {
const engine = {
name: 'Gecko',
name: ENGINE_MAP.Gecko,
};

const version = Utils.getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i, ua);
Expand All @@ -94,7 +95,7 @@ export default [
test: [/(apple)?webkit\/537\.36/i],
describe() {
return {
name: 'Blink',
name: ENGINE_MAP.Blink,
};
},
},
Expand All @@ -104,7 +105,7 @@ export default [
test: [/(apple)?webkit/i],
describe(ua) {
const engine = {
name: 'WebKit',
name: ENGINE_MAP.WebKit,
};

const version = Utils.getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i, ua);
Expand Down
25 changes: 13 additions & 12 deletions src/parser-os.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Utils from './utils.js';
import { OS_MAP } from './constants.js';

export default [
/* Windows Phone */
Expand All @@ -7,7 +8,7 @@ export default [
describe(ua) {
const version = Utils.getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i, ua);
return {
name: 'Windows Phone',
name: OS_MAP.WindowsPhone,
version,
};
},
Expand All @@ -21,7 +22,7 @@ export default [
const versionName = Utils.getWindowsVersionName(version);

return {
name: 'Windows',
name: OS_MAP.Windows,
version,
versionName,
};
Expand All @@ -34,7 +35,7 @@ export default [
describe(ua) {
const version = Utils.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, '.');
return {
name: 'macOS',
name: OS_MAP.MacOS,
version,
};
},
Expand All @@ -47,7 +48,7 @@ export default [
const version = Utils.getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i, ua).replace(/[_\s]/g, '.');

return {
name: 'iOS',
name: OS_MAP.iOS,
version,
};
},
Expand All @@ -64,7 +65,7 @@ export default [
const version = Utils.getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, ua);
const versionName = Utils.getAndroidVersionName(version);
const os = {
name: 'Android',
name: OS_MAP.Android,
version,
};
if (versionName) {
Expand All @@ -80,7 +81,7 @@ export default [
describe(ua) {
const version = Utils.getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i, ua);
const os = {
name: 'WebOS',
name: OS_MAP.WebOS,
};

if (version && version.length) {
Expand All @@ -99,7 +100,7 @@ export default [
|| Utils.getFirstMatch(/\bbb(\d+)/i, ua);

return {
name: 'BlackBerry',
name: OS_MAP.BlackBerry,
version,
};
},
Expand All @@ -112,7 +113,7 @@ export default [
const version = Utils.getFirstMatch(/bada\/(\d+(\.\d+)*)/i, ua);

return {
name: 'Bada',
name: OS_MAP.Bada,
version,
};
},
Expand All @@ -125,7 +126,7 @@ export default [
const version = Utils.getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i, ua);

return {
name: 'Tizen',
name: OS_MAP.Tizen,
version,
};
},
Expand All @@ -136,7 +137,7 @@ export default [
test: [/linux/i],
describe() {
return {
name: 'Linux',
name: OS_MAP.Linux,
};
},
},
Expand All @@ -146,7 +147,7 @@ export default [
test: [/CrOS/],
describe() {
return {
name: 'Chrome OS',
name: OS_MAP.ChromeOS,
};
},
},
Expand All @@ -157,7 +158,7 @@ export default [
describe(ua) {
const version = Utils.getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i, ua);
return {
name: 'PlayStation 4',
name: OS_MAP.PlayStation4,
version,
};
},
Expand Down
Loading