-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
124 lines (113 loc) · 2.78 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'use strict'
const data = new Map([
['Google Chrome for Android', [
'and_chr', // browserslist
'chrome android', // browserslist (no space)
'chrome for android',
'google chrome for android',
'android chrome'
]],
['Android Browser', [
'android', // airtap/zuul, browserslist, testling
'android browser', // airtap >= 4, testling (param-case)
'aosp'
]],
['iOS Safari', [
'ios_saf', // browserslist
'ios safari'
// Exclude these because they can be tied to a particular device simulator.
// 'iphone', // airtap/zuul, testling, sauce labs
// 'ipad' // airtap/zuul, testling, sauce labs
]],
['Microsoft Edge', [
'edge', // browserslist, karma
'msedge', // win-detect-browsers, @httptoolkit/browser-launcher
'microsoft edge' // airtap, sauce labs (no space)
]],
['Internet Explorer', [
'ie', // browserslist, karma, win-detect-browsers, @httptoolkit/browser-launcher, testling
'msie',
'internet explorer', // airtap/zuul, sauce labs
'iexplore', // airtap/zuul, testling
'iexplorer', // testling
'explorer', // testling
'explore' // testling
]],
['Google Chrome', [
'chrome', // *
'google chrome'
]],
['Mozilla Firefox', [
'firefox', // *
'mozilla firefox',
'ff' // testling
]],
['Beaker', [
'beaker'
]],
['Opera', [
'opera'
]],
['Opera Mini', [
'opera_mini',
'opera mini', // browserslist (no space)
'op_mini' // browserslist
]],
['Opera Mobile', [
'opera_mobile',
'opera mobile', // browserslist (no space)
'op_mob' // browserslist
]],
['Brave', [
'brave'
]],
['Maxthon', [
'maxthon'
]],
['Yandex', [
'yandex'
]],
['Safari', [
'safari'
]],
['Electron', [
'electron'
]],
['Node.js', [
'node', // browserslist
'nodejs',
'node.js'
]]
])
const index = new Map()
for (const [title, names] of data) {
for (let i = 0; i < names.length; i++) {
const name = names[i]
const snake = name.replace(/ /g, '_')
const param = name.replace(/ /g, '-')
const none = name.replace(/ /g, '')
for (const alt of [snake, param, none]) {
if (!names.includes(alt)) names.splice(1 + i++, 0, alt)
}
}
for (const name of names) {
if (index.has(name)) throw new Error('Names are not distinct')
index.set(name, title)
}
}
function names (name) {
const title = index.get(name.toLowerCase())
return title ? data.get(title) : []
}
function title (name) {
return index.get(name.toLowerCase())
}
function common (name) {
return names(name)[0]
}
module.exports = names
names.all = () => Array.from(index.keys())
names.title = title
names.title.all = () => Array.from(data.keys())
names.common = common
names.common.all = () => names.title.all().map(title => data.get(title)[0])