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

Use snake case for alias names

This commit is contained in:
Will Soares 2019-02-25 23:23:55 -03:00
parent a307533f74
commit 064aa812fc
3 changed files with 34 additions and 12 deletions

View File

@ -19,10 +19,17 @@ See the list in `test/acceptance/useragentstrings.yml` with example user agents
Whenever you add support for new browsers or notice a bug / mismatch, please update the list and check if all tests are still passing. Also, make sure to keep the list of browser aliases up-to-date in `src/constants.js`. Whenever you add support for new browsers or notice a bug / mismatch, please update the list and check if all tests are still passing. Also, make sure to keep the list of browser aliases up-to-date in `src/constants.js`.
For creating aliases, keep the following guidelines in mind: For creating aliases, keep the following guidelines in mind:
- use camelcase style for names - use snake_case style for names
- whenever possible drop the word `browser` from the original browser name - whenever possible drop the word `browser` from the original browser name
- remove all dashes from the original browser name - replace dashes with underscore
- avoid capital letters
- always check for possible duplicates - always check for possible duplicates
- aliases are supposed to also be a shorter version of the original name
Examples:
`Opera Coast` --> `opera_coast`
`UC Browser` --> `uc`
`SeaMonkey` --> `sea_monkey`
## Testing ## Testing

View File

@ -1,10 +1,10 @@
// NOTE: this list must be up-to-date with browsers listed in // NOTE: this list must be up-to-date with browsers listed in
// test/acceptance/useragentstrings.yml // test/acceptance/useragentstrings.yml
const BROWSER_ALIASES_MAP = { const BROWSER_ALIASES_MAP = {
'Amazon Silk': 'amazonSilk', 'Amazon Silk': 'amazon_silk',
'Android Browser': 'android', 'Android Browser': 'android',
Bada: 'bada', Bada: 'bada',
BlackBerry: 'blackBerry', BlackBerry: 'black_berry',
Chrome: 'chrome', Chrome: 'chrome',
Chromium: 'chromium', Chromium: 'chromium',
Epiphany: 'epiphany', Epiphany: 'epiphany',
@ -13,27 +13,27 @@ const BROWSER_ALIASES_MAP = {
Generic: 'generic', Generic: 'generic',
Googlebot: 'googlebot', Googlebot: 'googlebot',
'Internet Explorer': 'ie', 'Internet Explorer': 'ie',
'K-Meleon': 'kMeleon', 'K-Meleon': 'k_meleon',
Maxthon: 'maxthon', Maxthon: 'maxthon',
'Microsoft Edge': 'edge', 'Microsoft Edge': 'edge',
'MZ Browser': 'mz', 'MZ Browser': 'mz',
'NAVER Whale Browser': 'naver', 'NAVER Whale Browser': 'naver',
Opera: 'opera', Opera: 'opera',
'Opera Coast': 'operaCoast', 'Opera Coast': 'opera_coast',
PhantomJS: 'phantomJS', PhantomJS: 'phantom_js',
Puffin: 'puffin', Puffin: 'puffin',
QupZilla: 'qupZilla', QupZilla: 'qup_zilla',
Safari: 'safari', Safari: 'safari',
Sailfish: 'sailfish', Sailfish: 'sailfish',
SeaMonkey: 'seaMonkey', SeaMonkey: 'sea_monkey',
Sleipnir: 'sleipnir', Sleipnir: 'sleipnir',
Swing: 'swing', Swing: 'swing',
Tizen: 'tizen', Tizen: 'tizen',
'UC Browser': 'uc', 'UC Browser': 'uc',
Vivaldi: 'vivaldi', Vivaldi: 'vivaldi',
'WebOS Browser': 'webOS', 'WebOS Browser': 'web_os',
WeChat: 'weChat', WeChat: 'we_chat',
'Yandex Browser': 'yandex', 'Yandex Browser': 'yandex'
}; };
module.exports = { module.exports = {

15
test/unit/constants.js Normal file
View File

@ -0,0 +1,15 @@
import test from 'ava';
import { BROWSER_ALIASES_MAP } from '../../src/constants';
test('check duplicate aliases', (t) => {
const aliasesList = Object.keys(BROWSER_ALIASES_MAP).map(value => (BROWSER_ALIASES_MAP[value]));
let foundOnce, foundTwice;
const duplicates = aliasesList.filter(item => {
foundOnce = aliasesList.indexOf(item);
foundTwice = aliasesList.indexOf(item, foundOnce + 1);
return +foundTwice !== -1;
});
t.deepEqual(duplicates, []);
});