diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 648ae69..7400adf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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`. 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 - - remove all dashes from the original browser name + - replace dashes with underscore + - avoid capital letters - 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 diff --git a/src/constants.js b/src/constants.js index 99b543e..fe80944 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,10 +1,10 @@ // NOTE: this list must be up-to-date with browsers listed in // test/acceptance/useragentstrings.yml const BROWSER_ALIASES_MAP = { - 'Amazon Silk': 'amazonSilk', + 'Amazon Silk': 'amazon_silk', 'Android Browser': 'android', Bada: 'bada', - BlackBerry: 'blackBerry', + BlackBerry: 'black_berry', Chrome: 'chrome', Chromium: 'chromium', Epiphany: 'epiphany', @@ -13,27 +13,27 @@ const BROWSER_ALIASES_MAP = { Generic: 'generic', Googlebot: 'googlebot', 'Internet Explorer': 'ie', - 'K-Meleon': 'kMeleon', + 'K-Meleon': 'k_meleon', Maxthon: 'maxthon', 'Microsoft Edge': 'edge', 'MZ Browser': 'mz', 'NAVER Whale Browser': 'naver', Opera: 'opera', - 'Opera Coast': 'operaCoast', - PhantomJS: 'phantomJS', + 'Opera Coast': 'opera_coast', + PhantomJS: 'phantom_js', Puffin: 'puffin', - QupZilla: 'qupZilla', + QupZilla: 'qup_zilla', Safari: 'safari', Sailfish: 'sailfish', - SeaMonkey: 'seaMonkey', + SeaMonkey: 'sea_monkey', Sleipnir: 'sleipnir', Swing: 'swing', Tizen: 'tizen', 'UC Browser': 'uc', Vivaldi: 'vivaldi', - 'WebOS Browser': 'webOS', - WeChat: 'weChat', - 'Yandex Browser': 'yandex', + 'WebOS Browser': 'web_os', + WeChat: 'we_chat', + 'Yandex Browser': 'yandex' }; module.exports = { diff --git a/test/unit/constants.js b/test/unit/constants.js new file mode 100644 index 0000000..a8b2be6 --- /dev/null +++ b/test/unit/constants.js @@ -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, []); +});