bowser 2.5.2 → 2.6.1

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,559 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
-
5
- <meta charset="utf-8">
6
- <title>parser.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#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">parser.js</h1>
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
- <section>
44
- <article>
45
- <pre class="prettyprint source linenums"><code>import browserParsersList from './parser-browsers.js';
46
- import osParsersList from './parser-os.js';
47
- import platformParsersList from './parser-platforms.js';
48
- import enginesParsersList from './parser-engines.js';
49
- import Utils from './utils.js';
50
-
51
- /**
52
- * The main class that arranges the whole parsing process.
53
- */
54
- class Parser {
55
- /**
56
- * Create instance of Parser
57
- *
58
- * @param {String} UA User-Agent string
59
- * @param {Boolean} [skipParsing=false] parser can skip parsing in purpose of performance
60
- * improvements if you need to make a more particular parsing
61
- * like {@link Parser#parseBrowser} or {@link Parser#parsePlatform}
62
- *
63
- * @throw {Error} in case of empty UA String
64
- *
65
- * @constructor
66
- */
67
- constructor(UA, skipParsing = false) {
68
- if (UA === void (0) || UA === null || UA === '') {
69
- throw new Error("UserAgent parameter can't be empty");
70
- }
71
-
72
- this._ua = UA;
73
-
74
- /**
75
- * @typedef ParsedResult
76
- * @property {Object} browser
77
- * @property {String|undefined} [browser.name]
78
- * Browser name, like `"Chrome"` or `"Internet Explorer"`
79
- * @property {String|undefined} [browser.version] Browser version as a String `"12.01.45334.10"`
80
- * @property {Object} os
81
- * @property {String|undefined} [os.name] OS name, like `"Windows"` or `"macOS"`
82
- * @property {String|undefined} [os.version] OS version, like `"NT 5.1"` or `"10.11.1"`
83
- * @property {String|undefined} [os.versionName] OS name, like `"XP"` or `"High Sierra"`
84
- * @property {Object} platform
85
- * @property {String|undefined} [platform.type]
86
- * platform type, can be either `"desktop"`, `"tablet"` or `"mobile"`
87
- * @property {String|undefined} [platform.vendor] Vendor of the device,
88
- * like `"Apple"` or `"Samsung"`
89
- * @property {String|undefined} [platform.model] Device model,
90
- * like `"iPhone"` or `"Kindle Fire HD 7"`
91
- * @property {Object} engine
92
- * @property {String|undefined} [engine.name]
93
- * Can be any of this: `WebKit`, `Blink`, `Gecko`, `Trident`, `Presto`, `EdgeHTML`
94
- * @property {String|undefined} [engine.version] String version of the engine
95
- */
96
- this.parsedResult = {};
97
-
98
- if (skipParsing !== true) {
99
- this.parse();
100
- }
101
- }
102
-
103
- /**
104
- * Get UserAgent string of current Parser instance
105
- * @return {String} User-Agent String of the current &lt;Parser> object
106
- *
107
- * @public
108
- */
109
- getUA() {
110
- return this._ua;
111
- }
112
-
113
- /**
114
- * Test a UA string for a regexp
115
- * @param {RegExp} regex
116
- * @return {Boolean}
117
- */
118
- test(regex) {
119
- return regex.test(this._ua);
120
- }
121
-
122
- /**
123
- * Get parsed browser object
124
- * @return {Object}
125
- */
126
- parseBrowser() {
127
- this.parsedResult.browser = {};
128
-
129
- const browserDescriptor = browserParsersList.find((_browser) => {
130
- if (typeof _browser.test === 'function') {
131
- return _browser.test(this);
132
- }
133
-
134
- if (_browser.test instanceof Array) {
135
- return _browser.test.some(condition => this.test(condition));
136
- }
137
-
138
- throw new Error("Browser's test function is not valid");
139
- });
140
-
141
- if (browserDescriptor) {
142
- this.parsedResult.browser = browserDescriptor.describe(this.getUA());
143
- }
144
-
145
- return this.parsedResult.browser;
146
- }
147
-
148
- /**
149
- * Get parsed browser object
150
- * @return {Object}
151
- *
152
- * @public
153
- */
154
- getBrowser() {
155
- if (this.parsedResult.browser) {
156
- return this.parsedResult.browser;
157
- }
158
-
159
- return this.parseBrowser();
160
- }
161
-
162
- /**
163
- * Get browser's name
164
- * @return {String} Browser's name or an empty string
165
- *
166
- * @public
167
- */
168
- getBrowserName(toLowerCase) {
169
- if (toLowerCase) {
170
- return String(this.getBrowser().name).toLowerCase() || '';
171
- }
172
- return this.getBrowser().name || '';
173
- }
174
-
175
-
176
- /**
177
- * Get browser's version
178
- * @return {String} version of browser
179
- *
180
- * @public
181
- */
182
- getBrowserVersion() {
183
- return this.getBrowser().version;
184
- }
185
-
186
- /**
187
- * Get OS
188
- * @return {Object}
189
- *
190
- * @example
191
- * this.getOS();
192
- * {
193
- * name: 'macOS',
194
- * version: '10.11.12'
195
- * }
196
- */
197
- getOS() {
198
- if (this.parsedResult.os) {
199
- return this.parsedResult.os;
200
- }
201
-
202
- return this.parseOS();
203
- }
204
-
205
- /**
206
- * Parse OS and save it to this.parsedResult.os
207
- * @return {*|{}}
208
- */
209
- parseOS() {
210
- this.parsedResult.os = {};
211
-
212
- const os = osParsersList.find((_os) => {
213
- if (typeof _os.test === 'function') {
214
- return _os.test(this);
215
- }
216
-
217
- if (_os.test instanceof Array) {
218
- return _os.test.some(condition => this.test(condition));
219
- }
220
-
221
- throw new Error("Browser's test function is not valid");
222
- });
223
-
224
- if (os) {
225
- this.parsedResult.os = os.describe(this.getUA());
226
- }
227
-
228
- return this.parsedResult.os;
229
- }
230
-
231
- /**
232
- * Get OS name
233
- * @param {Boolean} [toLowerCase] return lower-cased value
234
- * @return {String} name of the OS — macOS, Windows, Linux, etc.
235
- */
236
- getOSName(toLowerCase) {
237
- const { name } = this.getOS();
238
-
239
- if (toLowerCase) {
240
- return String(name).toLowerCase() || '';
241
- }
242
-
243
- return name || '';
244
- }
245
-
246
- /**
247
- * Get OS version
248
- * @return {String} full version with dots ('10.11.12', '5.6', etc)
249
- */
250
- getOSVersion() {
251
- return this.getOS().version;
252
- }
253
-
254
- /**
255
- * Get parsed platform
256
- * @return {{}}
257
- */
258
- getPlatform() {
259
- if (this.parsedResult.platform) {
260
- return this.parsedResult.platform;
261
- }
262
-
263
- return this.parsePlatform();
264
- }
265
-
266
- /**
267
- * Get platform name
268
- * @param {Boolean} [toLowerCase=false]
269
- * @return {*}
270
- */
271
- getPlatformType(toLowerCase = false) {
272
- const { type } = this.getPlatform();
273
-
274
- if (toLowerCase) {
275
- return String(type).toLowerCase() || '';
276
- }
277
-
278
- return type || '';
279
- }
280
-
281
- /**
282
- * Get parsed platform
283
- * @return {{}}
284
- */
285
- parsePlatform() {
286
- this.parsedResult.platform = {};
287
-
288
- const platform = platformParsersList.find((_platform) => {
289
- if (typeof _platform.test === 'function') {
290
- return _platform.test(this);
291
- }
292
-
293
- if (_platform.test instanceof Array) {
294
- return _platform.test.some(condition => this.test(condition));
295
- }
296
-
297
- throw new Error("Browser's test function is not valid");
298
- });
299
-
300
- if (platform) {
301
- this.parsedResult.platform = platform.describe(this.getUA());
302
- }
303
-
304
- return this.parsedResult.platform;
305
- }
306
-
307
- /**
308
- * Get parsed engine
309
- * @return {{}}
310
- */
311
- getEngine() {
312
- if (this.parsedResult.engine) {
313
- return this.parsedResult.engine;
314
- }
315
-
316
- return this.parseEngine();
317
- }
318
-
319
- /**
320
- * Get engines's name
321
- * @return {String} Engines's name or an empty string
322
- *
323
- * @public
324
- */
325
- getEngineName(toLowerCase) {
326
- if (toLowerCase) {
327
- return String(this.getEngine().name).toLowerCase() || '';
328
- }
329
- return this.getEngine().name || '';
330
- }
331
-
332
- /**
333
- * Get parsed platform
334
- * @return {{}}
335
- */
336
- parseEngine() {
337
- this.parsedResult.engine = {};
338
-
339
- const engine = enginesParsersList.find((_engine) => {
340
- if (typeof _engine.test === 'function') {
341
- return _engine.test(this);
342
- }
343
-
344
- if (_engine.test instanceof Array) {
345
- return _engine.test.some(condition => this.test(condition));
346
- }
347
-
348
- throw new Error("Browser's test function is not valid");
349
- });
350
-
351
- if (engine) {
352
- this.parsedResult.engine = engine.describe(this.getUA());
353
- }
354
-
355
- return this.parsedResult.engine;
356
- }
357
-
358
- /**
359
- * Parse full information about the browser
360
- */
361
- parse() {
362
- this.parseBrowser();
363
- this.parseOS();
364
- this.parsePlatform();
365
- this.parseEngine();
366
-
367
- return this;
368
- }
369
-
370
- /**
371
- * Get parsed result
372
- * @return {ParsedResult}
373
- */
374
- getResult() {
375
- return Object.assign({}, this.parsedResult);
376
- }
377
-
378
- /**
379
- * Check if parsed browser matches certain conditions
380
- *
381
- * @param {Object} checkTree It's one or two layered object,
382
- * which can include a platform or an OS on the first layer
383
- * and should have browsers specs on the bottom-laying layer
384
- *
385
- * @returns {Boolean|undefined} Whether the browser satisfies the set conditions or not.
386
- * Returns `undefined` when the browser is no described in the checkTree object.
387
- *
388
- * @example
389
- * const browser = Bowser.getParser(window.navigator.userAgent);
390
- * if (browser.satisfies({chrome: '>118.01.1322' }))
391
- * // or with os
392
- * if (browser.satisfies({windows: { chrome: '>118.01.1322' } }))
393
- * // or with platforms
394
- * if (browser.satisfies({desktop: { chrome: '>118.01.1322' } }))
395
- */
396
- satisfies(checkTree) {
397
- const platformsAndOSes = {};
398
- let platformsAndOSCounter = 0;
399
- const browsers = {};
400
- let browsersCounter = 0;
401
-
402
- const allDefinitions = Object.keys(checkTree);
403
-
404
- allDefinitions.forEach((key) => {
405
- const currentDefinition = checkTree[key];
406
- if (typeof currentDefinition === 'string') {
407
- browsers[key] = currentDefinition;
408
- browsersCounter += 1;
409
- } else if (typeof currentDefinition === 'object') {
410
- platformsAndOSes[key] = currentDefinition;
411
- platformsAndOSCounter += 1;
412
- }
413
- });
414
-
415
- if (platformsAndOSCounter > 0) {
416
- const platformsAndOSNames = Object.keys(platformsAndOSes);
417
- const OSMatchingDefinition = platformsAndOSNames.find(name => (this.isOS(name)));
418
-
419
- if (OSMatchingDefinition) {
420
- const osResult = this.satisfies(platformsAndOSes[OSMatchingDefinition]);
421
-
422
- if (osResult !== void 0) {
423
- return osResult;
424
- }
425
- }
426
-
427
- const platformMatchingDefinition = platformsAndOSNames.find(name => (this.isPlatform(name)));
428
- if (platformMatchingDefinition) {
429
- const platformResult = this.satisfies(platformsAndOSes[platformMatchingDefinition]);
430
-
431
- if (platformResult !== void 0) {
432
- return platformResult;
433
- }
434
- }
435
- }
436
-
437
- if (browsersCounter > 0) {
438
- const browserNames = Object.keys(browsers);
439
- const matchingDefinition = browserNames.find(name => (this.isBrowser(name, true)));
440
-
441
- if (matchingDefinition !== void 0) {
442
- return this.compareVersion(browsers[matchingDefinition]);
443
- }
444
- }
445
-
446
- return undefined;
447
- }
448
-
449
- /**
450
- * Check if the browser name equals the passed string
451
- * @param browserName The string to compare with the browser name
452
- * @param [includingAlias=false] The flag showing whether alias will be included into comparison
453
- * @returns {boolean}
454
- */
455
- isBrowser(browserName, includingAlias = false) {
456
- const defaultBrowserName = this.getBrowserName().toLowerCase();
457
- let browserNameLower = browserName.toLowerCase();
458
- const alias = Utils.getBrowserTypeByAlias(browserNameLower);
459
-
460
- if (includingAlias &amp;&amp; alias) {
461
- browserNameLower = alias.toLowerCase();
462
- }
463
- return browserNameLower === defaultBrowserName;
464
- }
465
-
466
- compareVersion(version) {
467
- let expectedResults = [0];
468
- let comparableVersion = version;
469
- let isLoose = false;
470
-
471
- const currentBrowserVersion = this.getBrowserVersion();
472
-
473
- if (typeof currentBrowserVersion !== 'string') {
474
- return void 0;
475
- }
476
-
477
- if (version[0] === '>' || version[0] === '&lt;') {
478
- comparableVersion = version.substr(1);
479
- if (version[1] === '=') {
480
- isLoose = true;
481
- comparableVersion = version.substr(2);
482
- } else {
483
- expectedResults = [];
484
- }
485
- if (version[0] === '>') {
486
- expectedResults.push(1);
487
- } else {
488
- expectedResults.push(-1);
489
- }
490
- } else if (version[0] === '=') {
491
- comparableVersion = version.substr(1);
492
- } else if (version[0] === '~') {
493
- isLoose = true;
494
- comparableVersion = version.substr(1);
495
- }
496
-
497
- return expectedResults.indexOf(
498
- Utils.compareVersions(currentBrowserVersion, comparableVersion, isLoose),
499
- ) > -1;
500
- }
501
-
502
- isOS(osName) {
503
- return this.getOSName(true) === String(osName).toLowerCase();
504
- }
505
-
506
- isPlatform(platformType) {
507
- return this.getPlatformType(true) === String(platformType).toLowerCase();
508
- }
509
-
510
- isEngine(engineName) {
511
- return this.getEngineName(true) === String(engineName).toLowerCase();
512
- }
513
-
514
- /**
515
- * Is anything? Check if the browser is called "anything",
516
- * the OS called "anything" or the platform called "anything"
517
- * @param {String} anything
518
- * @returns {Boolean}
519
- */
520
- is(anything) {
521
- return this.isBrowser(anything) || this.isOS(anything) || this.isPlatform(anything);
522
- }
523
-
524
- /**
525
- * Check if any of the given values satisfies this.is(anything)
526
- * @param {String[]} anythings
527
- * @returns {Boolean}
528
- */
529
- some(anythings = []) {
530
- return anythings.some(anything => this.is(anything));
531
- }
532
- }
533
-
534
- export default Parser;
535
- </code></pre>
536
- </article>
537
- </section>
538
-
539
-
540
-
541
-
542
-
543
-
544
- </div>
545
-
546
- <br class="clear">
547
-
548
- <footer>
549
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Wed Jul 17 2019 13:52:37 GMT+0300 (Eastern European Summer Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
550
- </footer>
551
-
552
- <script>prettyPrint();</script>
553
- <script src="scripts/polyfill.js"></script>
554
- <script src="scripts/linenumber.js"></script>
555
-
556
-
557
-
558
- </body>
559
- </html>
@@ -1,20 +0,0 @@
1
- function hideAllButCurrent(){
2
- //by default all submenut items are hidden
3
- //but we need to rehide them for search
4
- document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) {
5
- parent.style.display = "none";
6
- });
7
-
8
- //only current page (if it exists) should be opened
9
- var file = window.location.pathname.split("/").pop().replace(/\.html/, '');
10
- document.querySelectorAll("nav > ul > li > a").forEach(function(parent) {
11
- var href = parent.attributes.href.value.replace(/\.html/, '');
12
- if (file === href) {
13
- parent.parentNode.querySelectorAll("ul li").forEach(function(elem) {
14
- elem.style.display = "block";
15
- });
16
- }
17
- });
18
- }
19
-
20
- hideAllButCurrent();