-
Notifications
You must be signed in to change notification settings - Fork 22
/
helper.js
256 lines (231 loc) · 5.08 KB
/
helper.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
const DEVICE_TYPES = require('./parser/const/device-type');
const DEVICE_TYPE_IDS = require('./parser/const/device-type-id');
const CLIENT_TYPES = require('./parser/const/client-type');
/**
* get device type string
* @param result
* @returns {string|null}
*/
const getDeviceType = (result) => {
return result.device && result.device.type ? result.device.type : null;
};
/**
* get device type id for name
* @param {string} name
* @returns {number|null}
*/
const getDeviceTypeIdForName = (name) => {
return name && DEVICE_TYPE_IDS[name] ? DEVICE_TYPE_IDS[name] : null;
};
/**
* get device type id
* @param result
* @returns {number|null}
*/
const getDeviceTypeId = (result) => {
return getDeviceTypeIdForName(getDeviceType(result))
};
/**
* get client type string
* @param result
* @returns {string|null}
*/
const getClientType = (result) => {
return result.client && result.client.type ? result.client.type : null;
};
/**
* is device type table
* @param result
* @returns {boolean}
*/
const isTablet = (result) => {
return getDeviceType(result) === DEVICE_TYPES.TABLET;
};
/**
* is device type phablet
* @param result
* @returns {boolean}
*/
const isPhablet = (result) => {
return getDeviceType(result) === DEVICE_TYPES.PHABLET;
};
/**
* is feature phone (push-button telephones)
* @param result
* @returns {boolean}
*/
const isFeaturePhone = (result) => {
return getDeviceType(result) === DEVICE_TYPES.FEATURE_PHONE;
};
/**
* is device type smartphone
* @param result
* @returns {boolean}
*/
const isSmartphone = (result) => {
return getDeviceType(result) === DEVICE_TYPES.SMARTPHONE;
};
/**
* is device type car
* @param result
* @returns {boolean}
*/
const isCar = (result) => {
return getDeviceType(result) === DEVICE_TYPES.CAR_BROWSER;
};
/**
* is device type mobile (feature phone, smartphone or phablet)
* @param result
* @returns {boolean}
*/
const isMobile = (result) => {
return isSmartphone(result) || isFeaturePhone(result) || isPhablet(result);
};
/**
* is device type desktop
* @param result
* @returns {boolean}
*/
const isDesktop = (result) => {
return getDeviceType(result) === DEVICE_TYPES.DESKTOP;
};
/**
* is os android
* @param result
* @returns {boolean}
*/
const isAndroid = (result) => {
return result.os && result.os.family === 'Android';
};
/**
* is os ios
* @param result
* @returns {boolean}
*/
const isIOS = (result) => {
return result.os && result.os.family === 'iOS';
};
/**
* is device type tv
* @param result
* @returns {boolean}
*/
const isTv = (result) => {
return getDeviceType(result) === DEVICE_TYPES.TV;
};
/**
* is device type console (xBox, PlayStation, Nintendo etc)
* @param result
* @returns {boolean}
*/
const isConsole = (result) => {
return getDeviceType(result) === DEVICE_TYPES.CONSOLE;
};
/**
* is device type portable camera
* @param result
* @returns {boolean}
*/
const isCamera = (result) => {
return getDeviceType(result) === DEVICE_TYPES.CAMERA;
};
/**
* is device type portable media player
* @param result
* @returns {boolean}
*/
const isPortableMediaPlayer = (result) => {
return getDeviceType(result) === DEVICE_TYPES.PORTABLE_MEDIA_PLAYER;
};
/**
* is device type smart speaker (Alisa, Alexa, HomePod etc)
* @param result
* @returns {boolean}
*/
const isSmartSpeaker = (result) => {
return getDeviceType(result) === DEVICE_TYPES.SMART_SPEAKER;
};
/**
* is device type peripheral (portable terminal, post terminal,
* single board computers, portable projector)
* @param result
* @returns {boolean}
*/
const isPeripheral = (result) => {
return getDeviceType(result) === DEVICE_TYPES.PERIPHERAL;
};
/**
* is device type smart display (LCD panel or interactive panel)
* @param result
* @returns {boolean}
*/
const isSmartDisplay = (result) => {
return getDeviceType(result) === DEVICE_TYPES.SMART_DISPLAY;
};
/**
* is device type wearable (watches, headsets)
* @param result
* @returns {boolean}
*/
const isWearable = (result) => {
return getDeviceType(result) === DEVICE_TYPES.WEARABLE;
};
/**
* is client type browser
* @param result
* @returns {boolean}
*/
const isBrowser = (result) => {
return getClientType(result) === CLIENT_TYPES.BROWSER;
};
/**
* is client type app (any type of client other than browser)
* @param result
* @returns {boolean}
*/
const isApp = (result) => {
return getClientType(result) !== null && !isBrowser(result);
};
/**
* is client type app desktop
* @param result
* @returns {boolean}
*/
const isDesktopApp = (result) => {
return isApp(result) && isDesktop(result);
};
/**
* is client type app mobile
* @param result
* @returns {boolean}
*/
const isMobileApp = (result) => {
return isApp(result) && (isMobile(result) || isTablet(result));
};
module.exports = {
getDeviceType,
getDeviceTypeId,
getDeviceTypeIdForName,
getClientType,
isCamera,
isCar,
isConsole,
isDesktop,
isFeaturePhone,
isMobile,
isPeripheral,
isPhablet,
isPortableMediaPlayer,
isSmartDisplay,
isSmartSpeaker,
isSmartphone,
isTablet,
isTv,
isWearable,
isAndroid,
isBrowser,
isApp,
isDesktopApp,
isMobileApp,
isIOS,
};