ua-parser-js 1.0.34 → 2.0.0-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
package/readme.md CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  # UAParser.js
14
14
 
15
- JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data with relatively small footprint (~17KB minified, ~6KB gzipped) that can be used either in browser (client-side) or node.js (server-side).
15
+ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model from User-Agent & Client-Hints data that can be used either in browser (client-side) or node.js (server-side).
16
16
 
17
17
  * Author : Faisal Salman <<f@faisalman.com>>
18
18
  * Demo : https://faisalman.github.io/ua-parser-js
@@ -26,7 +26,7 @@ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model fro
26
26
  </thead>
27
27
  <tbody>
28
28
  <tr>
29
- <td align="center" width="200px" rowspan="3"><a href="https://www.npmjs.com/package/@51degrees/ua-parser-js"><img src="images/51degrees.svg" alt="51degrees" width="75%" height="75%" ></a></td>
29
+ <td align="center" width="200px" rowspan="2"><a href="https://www.npmjs.com/package/@51degrees/ua-parser-js"><img src="images/51degrees.svg" alt="51degrees" width="75%" height="75%" ></a></td>
30
30
  <td align="left" width="400px"><a href="https://www.npmjs.com/package/@51degrees/ua-parser-js">↗ @51degrees/ua-parser-js</a></td>
31
31
  </tr>
32
32
  <tr>
@@ -34,46 +34,45 @@ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model fro
34
34
  </td>
35
35
  </tr>
36
36
  <tr>
37
- <td>
38
- <p>On 6 March, we’ll be hosting a demonstration of the 51Degrees UAParser. Register your place for the webinar <a href="https://event.webinarjam.com/register/36/6k2gqu5p">↗ here</a>.</p></td>
37
+ <td colspan="2">
38
+ <a href="https://opencollective.com/ua-parser-js">↗ Become a sponsor</a>
39
+ </td>
39
40
  </tr>
40
41
  </tbody>
41
42
  </table>
42
43
 
43
44
  ---
44
45
 
45
- # Documentation
46
- ### UAParser([user-agent][,extensions])
47
- typeof `user-agent` "string".
46
+ # Version 2.0
47
+ What's new & breaking, please read [CHANGELOG](changelog.md) before upgrading.
48
48
 
49
- typeof `extensions` "array".
49
+ # Documentation
50
+ ### UAParser([user-agent:string][,extensions:object][,headers:object(since@2.0)])
50
51
 
51
- In The Browser environment you dont need to pass the user-agent string to the function, you can just call the funtion and it should automatically get the string from the `window.navigator.userAgent`, but that is not the case in nodejs. The user-agent string must be passed in nodejs for the function to work.
52
- Usually you can find the user agent in:
53
- `request.headers["user-agent"]`.
52
+ In the browser environment you dont need to pass the user-agent string to the function, you can just call the funtion and it should automatically get the string from the `window.navigator.userAgent`, but that is not the case in nodejs. The user-agent string must be passed in' nodejs for the function to work. Usually you can find the user agent in: `request.headers["user-agent"]`.
54
53
 
55
54
 
56
55
  ## Constructor
57
- When you call `UAParser` with the `new` keyword `UAParser` will return a new instance with an empty result object, you have to call one of the available methods to get the information from the user-agent string.
56
+ When you call `UAParser` with the `new` keyword, `UAParser` will return a new instance with an empty result object, you have to call one of the available methods to get the information from the user-agent string.
58
57
  Like so:
59
- * `new UAParser([uastring][,extensions])`
58
+ * `new UAParser([user-agent:string][,extensions:object][,headers:object(since@2.0)])`
60
59
  ```js
61
- let parser = new UAParser("user-agent"); // you need to pass the user-agent for nodejs
60
+ let parser = new UAParser("your user-agent here"); // you need to pass the user-agent for nodejs
62
61
  console.log(parser); // {}
63
62
  let parserResults = parser.getResult();
64
63
  console.log(parserResults);
65
64
  /** {
66
- "ua": "",
67
- "browser": {},
68
- "engine": {},
69
- "os": {},
70
- "device": {},
71
- "cpu": {}
65
+ "ua" : "",
66
+ "browser" : {},
67
+ "engine" : {},
68
+ "os" : {},
69
+ "device" : {},
70
+ "cpu" : {}
72
71
  } */
73
72
  ```
74
73
 
75
74
  When you call UAParser without the `new` keyword, it will automatically call `getResult()` function and return the parsed results.
76
- * `UAParser([uastring][,extensions])`
75
+ * `UAParser([user-agent:string][,extensions:object][,headers:object(since@2.0)])`
77
76
  * returns result object `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
78
77
 
79
78
  ## Methods
@@ -91,7 +90,6 @@ The methods are self explanatory, here's a small overview on all the available m
91
90
  * `getUA()` - returns the user-agent string.
92
91
  * `setUA(user-agent)` - set a custom user-agent to be parsed.
93
92
 
94
-
95
93
  ---
96
94
 
97
95
  * `getResult()`
@@ -104,19 +102,19 @@ The methods are self explanatory, here's a small overview on all the available m
104
102
  # Possible 'browser.name':
105
103
  2345Explorer, 360 Browser, Amaya, Android Browser, Arora, Avant, Avast, AVG,
106
104
  BIDUBrowser, Baidu, Basilisk, Blazer, Bolt, Brave, Bowser, Camino, Chimera,
107
- Chrome Headless, Chrome WebView, Chrome, Chromium, Cobalt, Comodo Dragon, Dillo,
105
+ [Mobile] Chrome [Headless/WebView], Chromium, Cobalt, Comodo Dragon, Dillo,
108
106
  Dolphin, Doris, DuckDuckGo, Edge, Electron, Epiphany, Facebook, Falkon, Fennec,
109
- Firebird, Firefox [Focus/Reality], Flock, Flow, GSA, GoBrowser, Huawei Browser,
110
- ICE Browser, IE, IEMobile, IceApe, IceCat, IceDragon, Iceweasel, Instagram,
111
- Iridium, Iron, Jasmine, Kakao[Story/Talk], K-Meleon, Kindle, Klar, Konqueror,
112
- LBBROWSER, Line, LinkedIn, Links, Lunascape, Lynx, MIUI Browser, Maemo Browser,
113
- Maemo, Maxthon, MetaSr Midori, Minimo, Mobile Safari, Mosaic, Mozilla, NetFront,
107
+ Firebird, [Mobile] Firefox [Focus/Reality], Flock, Flow, GSA, GoBrowser, HeyTap,
108
+ Huawei Browser, ICE Browser, IE, IEMobile, IceApe, IceCat, IceDragon, Iceweasel,
109
+ Instagram, Iridium, Iron, Jasmine, Kakao[Story/Talk], K-Meleon, Kindle, Klar,
110
+ Konqueror, LBBROWSER, Line, LinkedIn, Links, Lunascape, Lynx, MIUI Browser,
111
+ Maemo Browser, Maemo, Maxthon, MetaSr Midori, Minimo, Mosaic, Mozilla, NetFront,
114
112
  NetSurf, Netfront, Netscape, NokiaBrowser, Obigo, Oculus Browser, OmniWeb,
115
113
  Opera Coast, Opera [Mini/Mobi/Tablet], PaleMoon, PhantomJS, Phoenix, Polaris,
116
- Puffin, QQ, QQBrowser, QQBrowserLite, Quark, QupZilla, RockMelt, Safari,
114
+ Puffin, QQ, QQBrowser, QQBrowserLite, Quark, QupZilla, RockMelt, [Mobile] Safari,
117
115
  Sailfish Browser, Samsung Browser, SeaMonkey, Silk, Skyfire, Sleipnir, Slim,
118
- SlimBrowser, Swiftfox, Tesla, Tizen Browser, UCBrowser, UP.Browser, Viera,
119
- Vivaldi, Waterfox, WeChat, Weibo, Yandex, baidu, iCab, w3m, Whale Browser...
116
+ SlimBrowser, Swiftfox, Tesla, TikTok, Tizen Browser, UCBrowser, UP.Browser, Viera,
117
+ Vivaldi, Waterfox, WeChat, Weibo, Yandex, baidu, iCab, w3m, Whale Browser, ...
120
118
 
121
119
  # 'browser.version' determined dynamically
122
120
  ```
@@ -150,8 +148,8 @@ Siemens, Sony[Ericsson], Sprint, Tesla, Vivo, Vodafone, Xbox, Xiaomi, Zebra, ZTE
150
148
 
151
149
  ```sh
152
150
  # Possible 'engine.name'
153
- Amaya, Blink, EdgeHTML, Flow, Gecko, Goanna, iCab, KHTML, Links, Lynx, NetFront,
154
- NetSurf, Presto, Tasman, Trident, w3m, WebKit
151
+ Amaya, Blink, EdgeHTML, Flow, Gecko, Goanna, iCab, KHTML, LibWeb, Links, Lynx,
152
+ NetFront, NetSurf, Presto, Tasman, Trident, w3m, WebKit
155
153
 
156
154
  # 'engine.version' determined dynamically
157
155
  ```
@@ -167,8 +165,9 @@ Fuchsia, Gentoo, GhostBSD, GNU, Haiku, HarmonyOS, HP-UX, Hurd, iOS, Joli, KaiOS,
167
165
  Linpus, Linspire,Linux, Mac OS, Maemo, Mageia, Mandriva, Manjaro, MeeGo, Minix,
168
166
  Mint, Morph OS, NetBSD, NetRange, NetTV, Nintendo, OpenBSD, OpenVMS, OS/2, Palm,
169
167
  PC-BSD, PCLinuxOS, Plan9, PlayStation, QNX, Raspbian, RedHat, RIM Tablet OS,
170
- RISC OS, Sabayon, Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen,
171
- Ubuntu, Unix, VectorLinux, Viera, watchOS, WebOS, Windows [Phone/Mobile], Zenwalk, ...
168
+ RISC OS, Sabayon, Sailfish, SerenityOS, Series40, Slackware, Solaris, SUSE, Symbian,
169
+ Tizen, Ubuntu, Unix, VectorLinux, Viera, watchOS, WebOS, Windows [Phone/Mobile],
170
+ Zenwalk, ...
172
171
 
173
172
  # 'os.version' determined dynamically
174
173
  ```
@@ -188,6 +187,198 @@ Ubuntu, Unix, VectorLinux, Viera, watchOS, WebOS, Windows [Phone/Mobile], Zenwal
188
187
  * set UA string to be parsed
189
188
  * returns current instance
190
189
 
190
+ #### * `is():boolean` utility `since@2.0`
191
+
192
+ ```js
193
+ // Is just a shorthand comparison to check whether the value of specified item equals one of its properties (in a case-insensitive way)
194
+ // so that instead of write it using `==` operator like this:
195
+
196
+ let ua = UAParser();
197
+ let device = ua.device;
198
+ let os = ua.os;
199
+
200
+ if (device.type == "mobile" && os.name != "iOS") {}
201
+ if (device.type == "smarttv" || device.vendor == "Samsung") {}
202
+
203
+ // we can also write the comparison above into as follow:
204
+
205
+ if (device.is("mobile") && !os.is("iOS")) {}
206
+ if (device.is("SmartTV") || device.is("SaMsUnG")) {}
207
+
208
+ /*
209
+ For device, properties will be checked in this particular order: type, model, vendor
210
+ */
211
+
212
+ // Another examples:
213
+
214
+ let uap = new UAParser('Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 635) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537');
215
+
216
+ uap.getBrowser().name; // "IEMobile"
217
+ uap.getBrowser().is("IEMobile"); // true
218
+ uap.getCPU().is("ARM"); // true
219
+
220
+ uap.getOS().name; // "Windows Phone"
221
+ uap.getOS().is("Windows Phone"); // true
222
+
223
+ uap.getDevice(); // { vendor: "Nokia", model: "Lumia 635", type: "mobile" }
224
+ uap.getResult().device; // { vendor: "Nokia", model: "Lumia 635", type: "mobile" }
225
+
226
+ let device = uap.getDevice();
227
+ device.is("mobile"); // true
228
+ device.is("Lumia 635"); // true
229
+ device.is("Nokia"); // true
230
+ device.is("iPhone"); // false
231
+ uap.getResult().device.is("Nokia"); // true
232
+ uap.getResult().device.model; // "Lumia 635"
233
+
234
+ uap.setUA("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36");
235
+
236
+ let browser = uap.getBrowser();
237
+ browser.is("IEMobile"); // false
238
+ browser.is("Chrome"); // true
239
+
240
+ uap.getResult().browser.is("Edge"); // false
241
+ uap.getResult().os.name // "Mac OS"
242
+ uap.getResult().os.is("Mac OS"); // true
243
+ uap.getResult().os.version; // "10.6.8"
244
+
245
+ let engine = uap.getEngine();
246
+ engine.is("Blink"); // true
247
+ ```
248
+
249
+ #### * `toString():string` utility `since@2.0`
250
+
251
+ ```js
252
+ // Retrieve full-name values as a string
253
+
254
+ /*
255
+ Values will be concatenated following this pattern:
256
+ * browser : name + version
257
+ * cpu : architecture
258
+ * device : vendor + model
259
+ * engine : name + version
260
+ * os : name + version
261
+ */
262
+
263
+ // Usage examples
264
+
265
+ let uap = new UAParser('Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 635) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537');
266
+
267
+ uap.getDevice(); // {
268
+ // vendor: "Nokia",
269
+ // model: "Lumia 635",
270
+ // type: "mobile"
271
+ // }
272
+ uap.getDevice().toString(); // "Nokia Lumia 635"
273
+
274
+ uap.getResult().os.name; // "Windows Phone"
275
+ uap.getResult().os.version; // "8.1"
276
+ uap.getResult().os.toString(); // "Windows Phone 8.1"
277
+
278
+ uap.setUA("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36");
279
+ uap.getBrowser().name; // "Chrome"
280
+ uap.getBrowser().version; // "28.0.1500.95"
281
+ uap.getBrowser().major; // "28"
282
+ uap.getBrowser().toString(); // "Chrome 28.0.1500.95"
283
+
284
+ let engine = uap.getEngine();
285
+ engine.name; // "Blink"
286
+ engine.version; // "28.0.1500.95"
287
+ engine.toString(); // "Blink 28.0.1500.95"
288
+ ```
289
+
290
+ #### * `withClientHints():Promise<object>|Thenable<object>` `since@2.0`
291
+
292
+ Recently Chrome limits the information exposed through user-agent and introduces a new experimental set of data called "client-hints". In browser-environment, obtaining the client-hints data via JavaScript must be done in an asynchronous way. In `UAParser` you can chain the result object from `get*` method with `withClientHints()` to also read the client-hints data from the browser and return the updated data as a `Promise`.
293
+
294
+ ```js
295
+ // client-side example
296
+ (async function () {
297
+ let ua = new UAParser();
298
+
299
+ // get browser data from user-agent only :
300
+ let browser = ua.getBrowser();
301
+ console.log('Using User-Agent: ', browser);
302
+
303
+ // get browser data from client-hints (with user-agent as fallback) :
304
+ browser = await ua.getBrowser().withClientHints();
305
+ console.log('Using Client-Hints: ', browser);
306
+
307
+ // alternatively :
308
+ ua.getBrowser().withClientHints().then(function (browser) {
309
+ console.log('Using Client-Hints: ', browser);
310
+ });
311
+ })();
312
+ ```
313
+
314
+ Along with `User-Agent` HTTP header, Chrome also sends this client-hints data by default under `Sec-CH-UA-*` HTTP headers in each request. In server-side development, you can capture this extra information by passing the `req.headers` to `UAParser()` (see examples below). When using `withClientHints()` in nodejs environment and browser without client-hints support (basically anything that's not Chromium-based) the updated data will be returned as a `Thenable` (has `then()` method).
315
+
316
+ ```js
317
+ // server-side example
318
+
319
+ // Suppose we got a request having these HTTP headers:
320
+ const request = {
321
+ headers : {
322
+ 'user-agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
323
+
324
+ 'sec-ch-ua-mobile' : '?1',
325
+ 'sec-ch-ua-model' : 'Galaxy S3 Marketing',
326
+ 'sec-ch-ua-platform' : 'Android'
327
+ }
328
+ };
329
+
330
+ const result1 = UAParser(request.headers); // parse only "user-agent" header
331
+ const result2 = UAParser(request.headers).withClientHints(); // update with "sec-ch-ua" headers
332
+
333
+ console.log(result1.os.name); // "Linux"
334
+ console.log(result1.device.type); // undefined
335
+ console.log(result1.device.model); // undefined
336
+
337
+ console.log(result2.os.name); // "Android"
338
+ console.log(result2.device.type); // "mobile"
339
+ console.log(result2.device.model); // "Galaxy S3 Marketing"
340
+
341
+ new UAParser(request.headers).getBrowser().withClientHints().then((browser) => {
342
+ console.log(browser.toString()); // Chrome 110.0.0.0
343
+ });
344
+ ```
345
+
346
+ ## Extending Regex
347
+
348
+ If you want to detect something that's not currently provided by UAParser.js (eg: `bots`, specific apps, etc), you can pass a list of regexes to extend internal UAParser.js regexes with your own.
349
+
350
+ * `UAParser([uastring,] extensions [,headers:object(since@2.0)])`
351
+
352
+ ```js
353
+ // Example:
354
+ const myOwnListOfBrowsers = [
355
+ [/(mybrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION, ['type', 'bot']]
356
+ ];
357
+
358
+ const myUA = 'Mozilla/5.0 MyBrowser/1.3';
359
+
360
+ let myParser = new UAParser({ browser: myOwnListOfBrowsers });
361
+
362
+ console.log(myParser.setUA(myUA).getBrowser()); // {name: "MyBrowser", version: "1.3", major: "1", type : "bot"}
363
+ console.log(myParser.getBrowser().is('bot')); // true
364
+
365
+ // Another example:
366
+ const myOwnListOfDevices = [
367
+ [/(mytab) ([\w ]+)/i], [UAParser.DEVICE.VENDOR, UAParser.DEVICE.MODEL, [UAParser.DEVICE.TYPE, UAParser.DEVICE.TABLET]],
368
+ [/(myphone)/i], [UAParser.DEVICE.VENDOR, [UAParser.DEVICE.TYPE, UAParser.DEVICE.MOBILE]]
369
+ ];
370
+
371
+ const myUA2 = 'Mozilla/5.0 MyTab 14 Pro Max';
372
+
373
+ let myParser2 = new UAParser({
374
+ browser: myOwnListOfBrowsers,
375
+ device: myOwnListOfDevices
376
+ });
377
+
378
+ console.log(myParser2.setUA(myUA2).getDevice()); // {vendor: "MyTab", model: "14 Pro Max", type: "tablet"}
379
+ ```
380
+
381
+
191
382
  # Usage
192
383
 
193
384
  ## Using HTML
@@ -199,8 +390,8 @@ Ubuntu, Unix, VectorLinux, Viera, watchOS, WebOS, Windows [Phone/Mobile], Zenwal
199
390
  <script src="ua-parser.min.js"></script>
200
391
  <script>
201
392
 
202
- var parser = new UAParser();
203
- console.log(parser.getResult());
393
+ var uap = new UAParser();
394
+ console.log(uap.getResult());
204
395
  /*
205
396
  /// This will print an object structured like this:
206
397
  {
@@ -208,7 +399,7 @@ Ubuntu, Unix, VectorLinux, Viera, watchOS, WebOS, Windows [Phone/Mobile], Zenwal
208
399
  browser: {
209
400
  name: "",
210
401
  version: "",
211
- major: "" //@deprecated
402
+ major: ""
212
403
  },
213
404
  engine: {
214
405
  name: "",
@@ -232,10 +423,10 @@ Ubuntu, Unix, VectorLinux, Viera, watchOS, WebOS, Windows [Phone/Mobile], Zenwal
232
423
 
233
424
  // Now let's try a custom user-agent string as an example
234
425
  var uastring1 = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2";
235
- parser.setUA(uastring1);
236
- var result = parser.getResult();
426
+ uap.setUA(uastring1);
427
+ var result = uap.getResult();
237
428
  // You can also use UAParser constructor directly without having to create an instance:
238
- // var result = UAParser(uastring1);
429
+ // var ua = UAParser(uastring1);
239
430
 
240
431
  console.log(result.browser); // {name: "Chromium", version: "15.0.874.106"}
241
432
  console.log(result.device); // {model: undefined, type: undefined, vendor: undefined}
@@ -246,14 +437,14 @@ Ubuntu, Unix, VectorLinux, Viera, watchOS, WebOS, Windows [Phone/Mobile], Zenwal
246
437
 
247
438
  // Do some other tests
248
439
  var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)";
249
- console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror"
250
- console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
251
- console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"}
440
+ console.log(uap.setUA(uastring2).getBrowser().name); // "Konqueror"
441
+ console.log(uap.getOS()); // {name: "OpenBSD", version: undefined}
442
+ console.log(uap.getEngine()); // {name: "KHTML", version: "4.1.4"}
252
443
 
253
444
  var uastring3 = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11';
254
- console.log(parser.setUA(uastring3).getDevice().model); // "PlayBook"
255
- console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
256
- console.log(parser.getBrowser().name); // "Safari"
445
+ console.log(uap.setUA(uastring3).getDevice().model); // "PlayBook"
446
+ console.log(uap.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
447
+ console.log(uap.getBrowser().name); // "Safari"
257
448
 
258
449
  </script>
259
450
  </head>
@@ -272,11 +463,24 @@ $ npm install ua-parser-js
272
463
 
273
464
  ```js
274
465
  var http = require('http');
275
- var parser = require('ua-parser-js');
466
+ var uap = require('ua-parser-js');
276
467
 
277
468
  http.createServer(function (req, res) {
278
469
  // get user-agent header
279
- var ua = parser(req.headers['user-agent']);
470
+ var ua = uap(req.headers['user-agent']);
471
+
472
+ /* // BEGIN since@2.0 - you can also pass client-hints data to UAParser
473
+
474
+ // note: only works in secure context (https:// or localhost or file://)
475
+
476
+ var getHighEntropyValues = 'Sec-CH-UA-Full-Version-List, Sec-CH-UA-Mobile, Sec-CH-UA-Model, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version, Sec-CH-UA-Arch, Sec-CH-UA-Bitness';
477
+ res.setHeader('Accept-CH', getHighEntropyValues);
478
+ res.setHeader('Critical-CH', getHighEntropyValues);
479
+
480
+ var ua = uap(req.headers);
481
+
482
+ // END since@2.0 */
483
+
280
484
  // write the result as response
281
485
  res.end(JSON.stringify(ua, null, ' '));
282
486
  })
@@ -285,6 +489,19 @@ http.createServer(function (req, res) {
285
489
  console.log('Server running at http://127.0.0.1:1337/');
286
490
  ```
287
491
 
492
+ ## Using ES Modules
493
+
494
+ ```js
495
+ import { UAParser } from 'ua-parser-js';
496
+
497
+ const { browser, cpu, device } = UAParser('Mozilla/5.0 (X11; U; Linux armv7l; en-GB; rv:1.9.2a1pre) Gecko/20090928 Firefox/3.5 Maemo Browser 1.4.1.22 RX-51 N900');
498
+
499
+ console.log(browser.name); // Maemo Browser
500
+ console.log(cpu.is('arm')); // true
501
+ console.log(device.is('mobile')); // true
502
+ console.log(device.model); // N900
503
+ ```
504
+
288
505
  ## Using TypeScript
289
506
 
290
507
  ```sh
@@ -320,20 +537,6 @@ console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
320
537
  $('body').addClass('ua-browser-' + $.ua.browser.name + ' ua-devicetype-' + $.ua.device.type);
321
538
  ```
322
539
 
323
- ## Using Extension
324
-
325
- * `UAParser([uastring,] extensions)`
326
-
327
- ```js
328
- // Example:
329
- var myOwnListOfBrowsers = [
330
- [/(mybrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]
331
- ];
332
- var myParser = new UAParser({ browser: myOwnListOfBrowsers });
333
- var myUA = 'Mozilla/5.0 MyBrowser/1.3';
334
- console.log(myParser.setUA(myUA).getBrowser()); // {name: "MyBrowser", version: "1.3"}
335
- ```
336
-
337
540
  # Development
338
541
 
339
542
  ## Backers & Sponsors
@@ -363,7 +566,7 @@ Made with [contributors-img](https://contrib.rocks).
363
566
 
364
567
  MIT License
365
568
 
366
- Copyright (c) 2012-2021 Faisal Salman <<f@faisalman.com>>
569
+ Copyright (c) 2012-2023 Faisal Salman <<f@faisalman.com>>
367
570
 
368
571
  Permission is hereby granted, free of charge, to any person obtaining a copy
369
572
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,101 @@
1
+ ///////////////////////////////////////////////
2
+ /* Enums for UAParser.js v2.0.0-alpha.1
3
+ https://github.com/faisalman/ua-parser-js
4
+ Author: Faisal Salman <f@faisalman.com>
5
+ MIT License */
6
+ //////////////////////////////////////////////
7
+
8
+ const BrowserName = Object.freeze({
9
+ CHROME : 'Chrome',
10
+ EDGE : 'Edge',
11
+ SAFARI : 'Safari',
12
+ FIREFOX : 'Firefox',
13
+ OPERA : 'Opera',
14
+ MOBILE_CHROME : 'Mobile Chrome',
15
+ MOBILE_SAFARI : 'Mobile Safari',
16
+ MOBILE_FIREFOX : 'Mobile Firefox',
17
+ ANDROID_BROWSER : 'Android Browser'
18
+
19
+ // TODO : test!
20
+ });
21
+
22
+ const CPUArch = Object.freeze({
23
+ IA32 : 'ia32',
24
+ AMD64 : 'amd64',
25
+ IA64 : 'ia64',
26
+ ARM : 'arm',
27
+ ARM64 : 'arm64',
28
+ ARMHF : 'armhf',
29
+ _68K : '68k',
30
+ AVR : 'avr',
31
+ IRIX : 'irix',
32
+ IRIX64 : 'irix64',
33
+ MIPS : 'mips',
34
+ MIPS64 : 'mips64',
35
+ PPC : 'ppc',
36
+ SPARC : 'sparc',
37
+ SPARC64 : 'sparc64'
38
+ });
39
+
40
+ const DeviceType = Object.freeze({
41
+ MOBILE : 'mobile',
42
+ TABLET : 'tablet',
43
+ SMARTTV : 'smarttv',
44
+ CONSOLE : 'console',
45
+ WEARABLE: 'wearable',
46
+ EMBEDDED: 'embedded'
47
+ });
48
+
49
+ const DeviceVendor = Object.freeze({
50
+ APPLE : 'Apple',
51
+ SAMSUNG : 'Samsung',
52
+ HUAWEI : 'Huawei',
53
+ XIAOMI : 'Xiaomi',
54
+ OPPO : 'OPPO',
55
+ VIVO : 'Vivo',
56
+ REALME : 'Realme',
57
+ LENOVO : 'Lenovo',
58
+ LG : 'LG'
59
+
60
+ // TODO : test!
61
+ });
62
+
63
+ const EngineName = Object.freeze({
64
+ AMAYA : 'Amaya',
65
+ BLINK : 'Blink',
66
+ EDGEHTML: 'EdgeHTML',
67
+ FLOW : 'Flow',
68
+ GECKO : 'Gecko',
69
+ GOANNA : 'Goanna',
70
+ ICAB : 'iCab',
71
+ LIBWEB : 'LibWeb',
72
+ KHTML : 'KHTML',
73
+ LINKS : 'Links',
74
+ LYNX : 'Lynx',
75
+ NETFRONT: 'NetFront',
76
+ NETSURF : 'NetSurf',
77
+ PRESTO : 'Presto',
78
+ TASMAN : 'Tasman',
79
+ TRIDENT : 'Trident',
80
+ W3M : 'w3m',
81
+ WEBKIT : 'WebKit'
82
+ });
83
+
84
+ const OSName = Object.freeze({
85
+ WINDOWS : 'Windows',
86
+ LINUX : 'Linux',
87
+ MACOS : 'macOS',
88
+ IOS : 'iOS',
89
+ ANDROID : 'Android'
90
+
91
+ // TODO : test!
92
+ });
93
+
94
+ module.exports = {
95
+ BrowserName,
96
+ CPUArch,
97
+ DeviceType,
98
+ DeviceVendor,
99
+ EngineName,
100
+ OSName
101
+ }
@@ -0,0 +1,105 @@
1
+ // Generated ESM version of UAParser.js enums
2
+ // DO NOT EDIT THIS FILE!
3
+ // Source: /src/enum/ua-parser-enum.js
4
+
5
+ ///////////////////////////////////////////////
6
+ /* Enums for UAParser.js v2.0.0-alpha.1
7
+ https://github.com/faisalman/ua-parser-js
8
+ Author: Faisal Salman <f@faisalman.com>
9
+ MIT License */
10
+ //////////////////////////////////////////////
11
+
12
+ const BrowserName = Object.freeze({
13
+ CHROME : 'Chrome',
14
+ EDGE : 'Edge',
15
+ SAFARI : 'Safari',
16
+ FIREFOX : 'Firefox',
17
+ OPERA : 'Opera',
18
+ MOBILE_CHROME : 'Mobile Chrome',
19
+ MOBILE_SAFARI : 'Mobile Safari',
20
+ MOBILE_FIREFOX : 'Mobile Firefox',
21
+ ANDROID_BROWSER : 'Android Browser'
22
+
23
+ // TODO : test!
24
+ });
25
+
26
+ const CPUArch = Object.freeze({
27
+ IA32 : 'ia32',
28
+ AMD64 : 'amd64',
29
+ IA64 : 'ia64',
30
+ ARM : 'arm',
31
+ ARM64 : 'arm64',
32
+ ARMHF : 'armhf',
33
+ _68K : '68k',
34
+ AVR : 'avr',
35
+ IRIX : 'irix',
36
+ IRIX64 : 'irix64',
37
+ MIPS : 'mips',
38
+ MIPS64 : 'mips64',
39
+ PPC : 'ppc',
40
+ SPARC : 'sparc',
41
+ SPARC64 : 'sparc64'
42
+ });
43
+
44
+ const DeviceType = Object.freeze({
45
+ MOBILE : 'mobile',
46
+ TABLET : 'tablet',
47
+ SMARTTV : 'smarttv',
48
+ CONSOLE : 'console',
49
+ WEARABLE: 'wearable',
50
+ EMBEDDED: 'embedded'
51
+ });
52
+
53
+ const DeviceVendor = Object.freeze({
54
+ APPLE : 'Apple',
55
+ SAMSUNG : 'Samsung',
56
+ HUAWEI : 'Huawei',
57
+ XIAOMI : 'Xiaomi',
58
+ OPPO : 'OPPO',
59
+ VIVO : 'Vivo',
60
+ REALME : 'Realme',
61
+ LENOVO : 'Lenovo',
62
+ LG : 'LG'
63
+
64
+ // TODO : test!
65
+ });
66
+
67
+ const EngineName = Object.freeze({
68
+ AMAYA : 'Amaya',
69
+ BLINK : 'Blink',
70
+ EDGEHTML: 'EdgeHTML',
71
+ FLOW : 'Flow',
72
+ GECKO : 'Gecko',
73
+ GOANNA : 'Goanna',
74
+ ICAB : 'iCab',
75
+ LIBWEB : 'LibWeb',
76
+ KHTML : 'KHTML',
77
+ LINKS : 'Links',
78
+ LYNX : 'Lynx',
79
+ NETFRONT: 'NetFront',
80
+ NETSURF : 'NetSurf',
81
+ PRESTO : 'Presto',
82
+ TASMAN : 'Tasman',
83
+ TRIDENT : 'Trident',
84
+ W3M : 'w3m',
85
+ WEBKIT : 'WebKit'
86
+ });
87
+
88
+ const OSName = Object.freeze({
89
+ WINDOWS : 'Windows',
90
+ LINUX : 'Linux',
91
+ MACOS : 'macOS',
92
+ IOS : 'iOS',
93
+ ANDROID : 'Android'
94
+
95
+ // TODO : test!
96
+ });
97
+
98
+ export {
99
+ BrowserName,
100
+ CPUArch,
101
+ DeviceType,
102
+ DeviceVendor,
103
+ EngineName,
104
+ OSName
105
+ }