bowser 2.5.3 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,328 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
-
5
- <meta charset="utf-8">
6
- <title>utils.js - Documentation</title>
7
-
8
-
9
- <script src="scripts/prettify/prettify.js"></script>
10
- <script src="scripts/prettify/lang-css.js"></script>
11
- <!--[if lt IE 9]>
12
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
13
- <![endif]-->
14
- <link type="text/css" rel="stylesheet" href="styles/prettify.css">
15
- <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
16
- <script src="scripts/nav.js" defer></script>
17
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
18
- </head>
19
- <body>
20
-
21
- <input type="checkbox" id="nav-trigger" class="nav-trigger" />
22
- <label for="nav-trigger" class="navicon-button x">
23
- <div class="navicon"></div>
24
- </label>
25
-
26
- <label for="nav-trigger" class="overlay"></label>
27
-
28
- <nav >
29
-
30
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Bowser.html">Bowser</a><ul class='methods'><li data-type='method'><a href="Bowser.html#.getParser">getParser</a></li><li data-type='method'><a href="Bowser.html#.parse">parse</a></li></ul></li><li><a href="Parser.html">Parser</a><ul class='methods'><li data-type='method'><a href="Parser.html#getBrowser">getBrowser</a></li><li data-type='method'><a href="Parser.html#getBrowserName">getBrowserName</a></li><li data-type='method'><a href="Parser.html#getBrowserVersion">getBrowserVersion</a></li><li data-type='method'><a href="Parser.html#getEngine">getEngine</a></li><li data-type='method'><a href="Parser.html#getEngineName">getEngineName</a></li><li data-type='method'><a href="Parser.html#getOS">getOS</a></li><li data-type='method'><a href="Parser.html#getOSName">getOSName</a></li><li data-type='method'><a href="Parser.html#getOSVersion">getOSVersion</a></li><li data-type='method'><a href="Parser.html#getPlatform">getPlatform</a></li><li data-type='method'><a href="Parser.html#getPlatformType">getPlatformType</a></li><li data-type='method'><a href="Parser.html#getResult">getResult</a></li><li data-type='method'><a href="Parser.html#getUA">getUA</a></li><li data-type='method'><a href="Parser.html#is">is</a></li><li data-type='method'><a href="Parser.html#isBrowser">isBrowser</a></li><li data-type='method'><a href="Parser.html#parse">parse</a></li><li data-type='method'><a href="Parser.html#parseBrowser">parseBrowser</a></li><li data-type='method'><a href="Parser.html#parseEngine">parseEngine</a></li><li data-type='method'><a href="Parser.html#parseOS">parseOS</a></li><li data-type='method'><a href="Parser.html#parsePlatform">parsePlatform</a></li><li data-type='method'><a href="Parser.html#satisfies">satisfies</a></li><li data-type='method'><a href="Parser.html#some">some</a></li><li data-type='method'><a href="Parser.html#test">test</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#getAndroidVersionName">getAndroidVersionName</a></li><li><a href="global.html#getBrowserAlias">getBrowserAlias</a></li><li><a href="global.html#getBrowserTypeByAlias">getBrowserTypeByAlias</a></li><li><a href="global.html#getFirstMatch">getFirstMatch</a></li><li><a href="global.html#getMacOSVersionName">getMacOSVersionName</a></li><li><a href="global.html#getSecondMatch">getSecondMatch</a></li><li><a href="global.html#getVersionPrecision">getVersionPrecision</a></li><li><a href="global.html#map">map</a></li><li><a href="global.html#matchAndReturnConst">matchAndReturnConst</a></li></ul>
31
- </nav>
32
-
33
- <div id="main">
34
-
35
- <h1 class="page-title">utils.js</h1>
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
- <section>
44
- <article>
45
- <pre class="prettyprint source linenums"><code>import { BROWSER_MAP, BROWSER_ALIASES_MAP } from './constants.js';
46
-
47
- export default class Utils {
48
- /**
49
- * Get first matched item for a string
50
- * @param {RegExp} regexp
51
- * @param {String} ua
52
- * @return {Array|{index: number, input: string}|*|boolean|string}
53
- */
54
- static getFirstMatch(regexp, ua) {
55
- const match = ua.match(regexp);
56
- return (match &amp;&amp; match.length > 0 &amp;&amp; match[1]) || '';
57
- }
58
-
59
- /**
60
- * Get second matched item for a string
61
- * @param regexp
62
- * @param {String} ua
63
- * @return {Array|{index: number, input: string}|*|boolean|string}
64
- */
65
- static getSecondMatch(regexp, ua) {
66
- const match = ua.match(regexp);
67
- return (match &amp;&amp; match.length > 1 &amp;&amp; match[2]) || '';
68
- }
69
-
70
- /**
71
- * Match a regexp and return a constant or undefined
72
- * @param {RegExp} regexp
73
- * @param {String} ua
74
- * @param {*} _const Any const that will be returned if regexp matches the string
75
- * @return {*}
76
- */
77
- static matchAndReturnConst(regexp, ua, _const) {
78
- if (regexp.test(ua)) {
79
- return _const;
80
- }
81
- return void (0);
82
- }
83
-
84
- static getWindowsVersionName(version) {
85
- switch (version) {
86
- case 'NT': return 'NT';
87
- case 'XP': return 'XP';
88
- case 'NT 5.0': return '2000';
89
- case 'NT 5.1': return 'XP';
90
- case 'NT 5.2': return '2003';
91
- case 'NT 6.0': return 'Vista';
92
- case 'NT 6.1': return '7';
93
- case 'NT 6.2': return '8';
94
- case 'NT 6.3': return '8.1';
95
- case 'NT 10.0': return '10';
96
- default: return undefined;
97
- }
98
- }
99
-
100
- /**
101
- * Get macOS version name
102
- * 10.5 - Leopard
103
- * 10.6 - Snow Leopard
104
- * 10.7 - Lion
105
- * 10.8 - Mountain Lion
106
- * 10.9 - Mavericks
107
- * 10.10 - Yosemite
108
- * 10.11 - El Capitan
109
- * 10.12 - Sierra
110
- * 10.13 - High Sierra
111
- * 10.14 - Mojave
112
- * 10.15 - Catalina
113
- *
114
- * @example
115
- * getMacOSVersionName("10.14") // 'Mojave'
116
- *
117
- * @param {string} version
118
- * @return {string} versionName
119
- */
120
- static getMacOSVersionName(version) {
121
- const v = version.split('.').splice(0, 2).map(s => parseInt(s, 10) || 0);
122
- v.push(0);
123
- if (v[0] !== 10) return undefined;
124
- switch (v[1]) {
125
- case 5: return 'Leopard';
126
- case 6: return 'Snow Leopard';
127
- case 7: return 'Lion';
128
- case 8: return 'Mountain Lion';
129
- case 9: return 'Mavericks';
130
- case 10: return 'Yosemite';
131
- case 11: return 'El Capitan';
132
- case 12: return 'Sierra';
133
- case 13: return 'High Sierra';
134
- case 14: return 'Mojave';
135
- case 15: return 'Catalina';
136
- default: return undefined;
137
- }
138
- }
139
-
140
- /**
141
- * Get Android version name
142
- * 1.5 - Cupcake
143
- * 1.6 - Donut
144
- * 2.0 - Eclair
145
- * 2.1 - Eclair
146
- * 2.2 - Froyo
147
- * 2.x - Gingerbread
148
- * 3.x - Honeycomb
149
- * 4.0 - Ice Cream Sandwich
150
- * 4.1 - Jelly Bean
151
- * 4.4 - KitKat
152
- * 5.x - Lollipop
153
- * 6.x - Marshmallow
154
- * 7.x - Nougat
155
- * 8.x - Oreo
156
- * 9.x - Pie
157
- *
158
- * @example
159
- * getAndroidVersionName("7.0") // 'Nougat'
160
- *
161
- * @param {string} version
162
- * @return {string} versionName
163
- */
164
- static getAndroidVersionName(version) {
165
- const v = version.split('.').splice(0, 2).map(s => parseInt(s, 10) || 0);
166
- v.push(0);
167
- if (v[0] === 1 &amp;&amp; v[1] &lt; 5) return undefined;
168
- if (v[0] === 1 &amp;&amp; v[1] &lt; 6) return 'Cupcake';
169
- if (v[0] === 1 &amp;&amp; v[1] >= 6) return 'Donut';
170
- if (v[0] === 2 &amp;&amp; v[1] &lt; 2) return 'Eclair';
171
- if (v[0] === 2 &amp;&amp; v[1] === 2) return 'Froyo';
172
- if (v[0] === 2 &amp;&amp; v[1] > 2) return 'Gingerbread';
173
- if (v[0] === 3) return 'Honeycomb';
174
- if (v[0] === 4 &amp;&amp; v[1] &lt; 1) return 'Ice Cream Sandwich';
175
- if (v[0] === 4 &amp;&amp; v[1] &lt; 4) return 'Jelly Bean';
176
- if (v[0] === 4 &amp;&amp; v[1] >= 4) return 'KitKat';
177
- if (v[0] === 5) return 'Lollipop';
178
- if (v[0] === 6) return 'Marshmallow';
179
- if (v[0] === 7) return 'Nougat';
180
- if (v[0] === 8) return 'Oreo';
181
- if (v[0] === 9) return 'Pie';
182
- return undefined;
183
- }
184
-
185
- /**
186
- * Get version precisions count
187
- *
188
- * @example
189
- * getVersionPrecision("1.10.3") // 3
190
- *
191
- * @param {string} version
192
- * @return {number}
193
- */
194
- static getVersionPrecision(version) {
195
- return version.split('.').length;
196
- }
197
-
198
- /**
199
- * Calculate browser version weight
200
- *
201
- * @example
202
- * compareVersions('1.10.2.1', '1.8.2.1.90') // 1
203
- * compareVersions('1.010.2.1', '1.09.2.1.90'); // 1
204
- * compareVersions('1.10.2.1', '1.10.2.1'); // 0
205
- * compareVersions('1.10.2.1', '1.0800.2'); // -1
206
- * compareVersions('1.10.2.1', '1.10', true); // 0
207
- *
208
- * @param {String} versionA versions versions to compare
209
- * @param {String} versionB versions versions to compare
210
- * @param {boolean} [isLoose] enable loose comparison
211
- * @return {Number} comparison result: -1 when versionA is lower,
212
- * 1 when versionA is bigger, 0 when both equal
213
- */
214
- /* eslint consistent-return: 1 */
215
- static compareVersions(versionA, versionB, isLoose = false) {
216
- // 1) get common precision for both versions, for example for "10.0" and "9" it should be 2
217
- const versionAPrecision = Utils.getVersionPrecision(versionA);
218
- const versionBPrecision = Utils.getVersionPrecision(versionB);
219
-
220
- let precision = Math.max(versionAPrecision, versionBPrecision);
221
- let lastPrecision = 0;
222
-
223
- const chunks = Utils.map([versionA, versionB], (version) => {
224
- const delta = precision - Utils.getVersionPrecision(version);
225
-
226
- // 2) "9" -> "9.0" (for precision = 2)
227
- const _version = version + new Array(delta + 1).join('.0');
228
-
229
- // 3) "9.0" -> ["000000000"", "000000009"]
230
- return Utils.map(_version.split('.'), chunk => new Array(20 - chunk.length).join('0') + chunk).reverse();
231
- });
232
-
233
- // adjust precision for loose comparison
234
- if (isLoose) {
235
- lastPrecision = precision - Math.min(versionAPrecision, versionBPrecision);
236
- }
237
-
238
- // iterate in reverse order by reversed chunks array
239
- precision -= 1;
240
- while (precision >= lastPrecision) {
241
- // 4) compare: "000000009" > "000000010" = false (but "9" > "10" = true)
242
- if (chunks[0][precision] > chunks[1][precision]) {
243
- return 1;
244
- }
245
-
246
- if (chunks[0][precision] === chunks[1][precision]) {
247
- if (precision === lastPrecision) {
248
- // all version chunks are same
249
- return 0;
250
- }
251
-
252
- precision -= 1;
253
- } else if (chunks[0][precision] &lt; chunks[1][precision]) {
254
- return -1;
255
- }
256
- }
257
- }
258
-
259
- /**
260
- * Array::map polyfill
261
- *
262
- * @param {Array} arr
263
- * @param {Function} iterator
264
- * @return {Array}
265
- */
266
- static map(arr, iterator) {
267
- const result = [];
268
- let i;
269
- if (Array.prototype.map) {
270
- return Array.prototype.map.call(arr, iterator);
271
- }
272
- for (i = 0; i &lt; arr.length; i += 1) {
273
- result.push(iterator(arr[i]));
274
- }
275
- return result;
276
- }
277
-
278
- /**
279
- * Get short version/alias for a browser name
280
- *
281
- * @example
282
- * getBrowserAlias('Microsoft Edge') // edge
283
- *
284
- * @param {string} browserName
285
- * @return {string}
286
- */
287
- static getBrowserAlias(browserName) {
288
- return BROWSER_ALIASES_MAP[browserName];
289
- }
290
-
291
- /**
292
- * Get short version/alias for a browser name
293
- *
294
- * @example
295
- * getBrowserAlias('edge') // Microsoft Edge
296
- *
297
- * @param {string} browserName
298
- * @return {string}
299
- */
300
- static getBrowserTypeByAlias(browserAlia) {
301
- return BROWSER_MAP[browserAlia] || '';
302
- }
303
- }
304
- </code></pre>
305
- </article>
306
- </section>
307
-
308
-
309
-
310
-
311
-
312
-
313
- </div>
314
-
315
- <br class="clear">
316
-
317
- <footer>
318
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Aug 04 2019 23:53:02 GMT+0300 (Eastern European Summer Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
319
- </footer>
320
-
321
- <script>prettyPrint();</script>
322
- <script src="scripts/polyfill.js"></script>
323
- <script src="scripts/linenumber.js"></script>
324
-
325
-
326
-
327
- </body>
328
- </html>