@hyperwatch/useragent 3.9.3 → 4.0.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,6 +1,6 @@
1
1
  [
2
2
  {
3
- "regex": "^.{0,100}?(?:(?:iPhone|Windows CE|Windows Phone|Android).{0,300}(?:(?:Bot|Yeti)-Mobile|YRSpider|BingPreview|bots?/\\d|(?:bot|spider)\\.html)|AdsBot-Google-Mobile.{0,200}iPhone)",
3
+ "regex": "^.{0,100}?(?:(?:iPhone|Windows CE|Windows Phone|Android).{0,300}(?:(?:Bot|Yeti)-Mobile|YRSpider|BingPreview|bots?/\\d|(?:bot|spider)\\.html|Google-InspectionTool)|AdsBot-Google-Mobile.{0,200}iPhone)",
4
4
  "regex_flag": "i",
5
5
  "device_replacement": "Spider",
6
6
  "brand_replacement": "Spider",
@@ -24,13 +24,13 @@
24
24
  "brand_replacement": "Spider"
25
25
  },
26
26
  {
27
- "regex": "Mozilla.{1,100}Mobile.{1,100}AspiegelBot",
27
+ "regex": "Mozilla.{1,100}Mobile.{1,100}(AspiegelBot|PetalBot)",
28
28
  "device_replacement": "Spider",
29
29
  "brand_replacement": "Spider",
30
30
  "model_replacement": "Smartphone"
31
31
  },
32
32
  {
33
- "regex": "Mozilla.{0,200}AspiegelBot",
33
+ "regex": "Mozilla.{0,200}(AspiegelBot|PetalBot)",
34
34
  "device_replacement": "Spider",
35
35
  "brand_replacement": "Spider",
36
36
  "model_replacement": "Desktop"
@@ -504,6 +504,30 @@
504
504
  "brand_replacement": "ChangJia",
505
505
  "model_replacement": "$1"
506
506
  },
507
+ {
508
+ "regex": "CrKey.*DeviceType/([^/]*)",
509
+ "brand_replacement": "Google",
510
+ "device_replacement": "Chromecast",
511
+ "model_replacement": "$1"
512
+ },
513
+ {
514
+ "regex": "Fuchsia.*CrKey",
515
+ "brand_replacement": "Google",
516
+ "device_replacement": "Chromecast",
517
+ "model_replacement": "Nest Hub"
518
+ },
519
+ {
520
+ "regex": "Linux.*CrKey/1.36",
521
+ "brand_replacement": "Google",
522
+ "device_replacement": "Chromecast",
523
+ "model_replacement": "First Generation"
524
+ },
525
+ {
526
+ "regex": "CrKey/",
527
+ "brand_replacement": "Google",
528
+ "device_replacement": "Chromecast",
529
+ "model_replacement": "Chromecast"
530
+ },
507
531
  {
508
532
  "regex": "; {0,2}(Cloudfone)[ _](Excite)([^ ][^;/]{1,100}?)(?: Build|\\) AppleWebKit)",
509
533
  "device_replacement": "$1 $2 $3",
@@ -1072,7 +1096,7 @@
1072
1096
  "model_replacement": "$1"
1073
1097
  },
1074
1098
  {
1075
- "regex": "; {0,2}(ADR6200|ADR6400L|ADR6425LVW|Amaze|DesireS?|EndeavorU|Eris|EVO|Evo\\d[A-Z]+|HD2|IncredibleS?|Inspire[A-Z0-9]*|Inspire[A-Z0-9]*|Sensation[A-Z0-9]*|Wildfire)[ _-](.{1,200}?)(?:[/;\\)]|Build|MIUI|1\\.0)",
1099
+ "regex": "; {0,2}(ADR6200|ADR6400L|ADR6425LVW|Amaze|DesireS?|EndeavorU|Eris|EVO|Evo\\d[A-Z]+|HD2|IncredibleS?|Inspire[A-Z0-9]*|Sensation[A-Z0-9]*|Wildfire)[ _-](.{1,200}?)(?:[/;\\)]|Build|MIUI|1\\.0)",
1076
1100
  "regex_flag": "i",
1077
1101
  "device_replacement": "HTC $1 $2",
1078
1102
  "brand_replacement": "HTC",
@@ -1612,6 +1636,30 @@
1612
1636
  "brand_replacement": "Meizu",
1613
1637
  "model_replacement": "$1"
1614
1638
  },
1639
+ {
1640
+ "regex": "Quest 3",
1641
+ "device_replacement": "Quest",
1642
+ "brand_replacement": "Meta",
1643
+ "model_replacement": "Quest 3"
1644
+ },
1645
+ {
1646
+ "regex": "Quest 2",
1647
+ "device_replacement": "Quest",
1648
+ "brand_replacement": "Meta",
1649
+ "model_replacement": "Quest 2"
1650
+ },
1651
+ {
1652
+ "regex": "Quest Pro",
1653
+ "device_replacement": "Quest",
1654
+ "brand_replacement": "Meta",
1655
+ "model_replacement": "Quest Pro"
1656
+ },
1657
+ {
1658
+ "regex": "Quest",
1659
+ "device_replacement": "Quest",
1660
+ "brand_replacement": "Meta",
1661
+ "model_replacement": "Quest"
1662
+ },
1615
1663
  {
1616
1664
  "regex": "; {0,2}(?:Micromax[ _](A111|A240)|(A111|A240)) Build",
1617
1665
  "regex_flag": "i",
@@ -1895,13 +1943,13 @@
1895
1943
  "model_replacement": "$1"
1896
1944
  },
1897
1945
  {
1898
- "regex": "; (ONE [a-zA-Z]\\d+)(?: Build|\\) AppleWebKit)",
1946
+ "regex": "; (ONE [a-zA-Z]\\d+)(?: Build|;? {0,2}\\) AppleWebKit)",
1899
1947
  "device_replacement": "OnePlus $1",
1900
1948
  "brand_replacement": "OnePlus",
1901
1949
  "model_replacement": "$1"
1902
1950
  },
1903
1951
  {
1904
- "regex": "; (ONEPLUS [a-zA-Z]\\d+)(?: Build|\\) AppleWebKit)",
1952
+ "regex": "; (ONEPLUS [a-zA-Z]\\d+)(?: Build|;? {0,2}\\) AppleWebKit)",
1905
1953
  "device_replacement": "OnePlus $1",
1906
1954
  "brand_replacement": "OnePlus",
1907
1955
  "model_replacement": "$1"
@@ -3546,7 +3594,7 @@
3546
3594
  "model_replacement": "Wii U"
3547
3595
  },
3548
3596
  {
3549
- "regex": "Nintendo (DS|3DS|DSi|Wii);",
3597
+ "regex": "Nintendo (Switch|DS|3DS|DSi|Wii);",
3550
3598
  "device_replacement": "Nintendo $1",
3551
3599
  "brand_replacement": "Nintendo",
3552
3600
  "model_replacement": "$1"
@@ -3742,7 +3790,7 @@
3742
3790
  "model_replacement": "Smartphone"
3743
3791
  },
3744
3792
  {
3745
- "regex": "^.{0,100}(bot|BUbiNG|zao|borg|DBot|oegp|silk|Xenu|zeal|^NING|CCBot|crawl|htdig|lycos|slurp|teoma|voila|yahoo|Sogou|CiBra|Nutch|^Java/|^JNLP/|Daumoa|Daum|Genieo|ichiro|larbin|pompos|Scrapy|snappy|speedy|spider|msnbot|msrbot|vortex|^vortex|crawler|favicon|indexer|Riddler|scooter|scraper|scrubby|WhatWeb|WinHTTP|bingbot|BingPreview|openbot|gigabot|furlbot|polybot|seekbot|^voyager|archiver|Icarus6j|mogimogi|Netvibes|blitzbot|altavista|charlotte|findlinks|Retreiver|TLSProber|WordPress|SeznamBot|ProoXiBot|wsr\\-agent|Squrl Java|EtaoSpider|PaperLiBot|SputnikBot|A6\\-Indexer|netresearch|searchsight|baiduspider|YisouSpider|ICC\\-Crawler|http%20client|Python-urllib|dataparksearch|converacrawler|Screaming Frog|AppEngine-Google|YahooCacheSystem|fast\\-webcrawler|Sogou Pic Spider|semanticdiscovery|Innovazion Crawler|facebookexternalhit|Google.{0,200}/\\+/web/snippet|Google-HTTP-Java-Client|BlogBridge|IlTrovatore-Setaccio|InternetArchive|GomezAgent|WebThumbnail|heritrix|NewsGator|PagePeeker|Reaper|ZooShot|holmes|NL-Crawler|Pingdom|StatusCake|WhatsApp|masscan|Google Web Preview|Qwantify|Yeti|OgScrper)",
3793
+ "regex": "^.{0,100}(bot|BUbiNG|zao|borg|DBot|oegp|silk|Xenu|zeal|^NING|CCBot|crawl|htdig|lycos|slurp|teoma|voila|yahoo|Sogou|CiBra|Nutch|^Java/|^JNLP/|Daumoa|Daum|Genieo|ichiro|larbin|pompos|Scrapy|snappy|speedy|spider|msnbot|msrbot|vortex|^vortex|crawler|favicon|indexer|Riddler|scooter|scraper|scrubby|WhatWeb|WinHTTP|bingbot|BingPreview|openbot|gigabot|furlbot|polybot|seekbot|^voyager|archiver|Icarus6j|mogimogi|Netvibes|blitzbot|altavista|charlotte|findlinks|Retreiver|TLSProber|WordPress|SeznamBot|ProoXiBot|wsr\\-agent|Squrl Java|EtaoSpider|PaperLiBot|SputnikBot|A6\\-Indexer|netresearch|searchsight|baiduspider|YisouSpider|ICC\\-Crawler|http%20client|Python-urllib|dataparksearch|converacrawler|Screaming Frog|AppEngine-Google|YahooCacheSystem|fast\\-webcrawler|Sogou Pic Spider|semanticdiscovery|Innovazion Crawler|facebookexternalhit|Google.{0,200}/\\+/web/snippet|Google-HTTP-Java-Client|BlogBridge|IlTrovatore-Setaccio|InternetArchive|GomezAgent|WebThumbnail|heritrix|NewsGator|PagePeeker|Reaper|ZooShot|holmes|NL-Crawler|Pingdom|StatusCake|WhatsApp|masscan|Google Web Preview|Qwantify|Yeti|OgScrper|RecipeRadar|GPTBot|Google-InspectionTool)",
3746
3794
  "regex_flag": "i",
3747
3795
  "device_replacement": "Spider",
3748
3796
  "brand_replacement": "Spider",
@@ -40,7 +40,7 @@
40
40
  "regex": "HbbTV/\\d+\\.\\d+\\.\\d+ \\(.{0,30}; ?([a-zA-Z]+) ?;.{0,30}(201[1-9]).{0,30}\\)"
41
41
  },
42
42
  {
43
- "regex": "AspiegelBot",
43
+ "regex": "AspiegelBot|PetalBot",
44
44
  "os_replacement": "Other"
45
45
  },
46
46
  {
@@ -56,6 +56,22 @@
56
56
  {
57
57
  "regex": "ArcGISRuntime-(?:Android|iOS)\\/\\d+\\.\\d+(?:\\.\\d+|) \\((Android|iOS) (\\d+)(?:\\.(\\d+)(?:\\.(\\d+)|)|);"
58
58
  },
59
+ {
60
+ "regex": "(Android) (\\d+)(?:\\.(\\d+)).*CrKey",
61
+ "os_replacement": "Chromecast Android"
62
+ },
63
+ {
64
+ "regex": "Fuchsia.*(CrKey)(?:[/](\\d+)\\.(\\d+)(?:\\.(\\d+)|)|)",
65
+ "os_replacement": "Chromecast Fuchsia"
66
+ },
67
+ {
68
+ "regex": "Linux.*(CrKey)(?:[/](\\d+)\\.(\\d+)(?:\\.(\\d+)|)|).*DeviceType/SmartSpeaker",
69
+ "os_replacement": "Chromecast SmartSpeaker"
70
+ },
71
+ {
72
+ "regex": "Linux.*(CrKey)(?:[/](\\d+)\\.(\\d+)(?:\\.(\\d+)|)|)",
73
+ "os_replacement": "Chromecast Linux"
74
+ },
59
75
  {
60
76
  "regex": "(Android)[ \\-/](\\d+)(?:\\.(\\d+)|)(?:[.\\-]([a-z0-9]+)|)"
61
77
  },
@@ -109,6 +125,10 @@
109
125
  "regex": "(android)\\s(?:mobile\\/)(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)|)|)",
110
126
  "os_replacement": "Android"
111
127
  },
128
+ {
129
+ "regex": "Quest",
130
+ "os_replacement": "Android"
131
+ },
112
132
  {
113
133
  "regex": "(Silk-Accelerated=[a-z]{4,5})",
114
134
  "os_replacement": "Android"
@@ -220,6 +240,10 @@
220
240
  {
221
241
  "regex": "(Tizen)[/ ](\\d+)\\.(\\d+)"
222
242
  },
243
+ {
244
+ "regex": "Intel Mac OS X.+(CriOS|EdgiOS)/\\d+",
245
+ "os_replacement": "iOS"
246
+ },
223
247
  {
224
248
  "regex": "((?:Mac[ +]?|; )OS[ +]X)[\\s+/](?:(\\d+)[_.](\\d+)(?:[_.](\\d+)|)|Mach-O)",
225
249
  "os_replacement": "Mac OS X"
@@ -272,6 +296,10 @@
272
296
  "regex": "^Box.{0,200};(Darwin)/(10)\\.(1\\d)(?:\\.(\\d+)|)",
273
297
  "os_replacement": "Mac OS X"
274
298
  },
299
+ {
300
+ "regex": "darwin; arm64",
301
+ "os_replacement": "Mac OS X"
302
+ },
275
303
  {
276
304
  "regex": "(Apple\\s?TV)(?:/(\\d+)\\.(\\d+)|)",
277
305
  "os_replacement": "ATV OS X"
@@ -679,6 +707,39 @@
679
707
  "os_replacement": "iOS",
680
708
  "os_v1_replacement": "15"
681
709
  },
710
+ {
711
+ "regex": "CFNetwork/.{0,100} Darwin/22\\.([0-5])\\.\\d+",
712
+ "os_replacement": "iOS",
713
+ "os_v1_replacement": "16",
714
+ "os_v2_replacement": "$1"
715
+ },
716
+ {
717
+ "regex": "CFNetwork/.{0,100} Darwin/(22)\\.\\d+",
718
+ "os_replacement": "iOS",
719
+ "os_v1_replacement": "16"
720
+ },
721
+ {
722
+ "regex": "CFNetwork/.{0,100} Darwin/23\\.([0-5])\\.\\d+",
723
+ "os_replacement": "iOS",
724
+ "os_v1_replacement": "17",
725
+ "os_v2_replacement": "$1"
726
+ },
727
+ {
728
+ "regex": "CFNetwork/.{0,100} Darwin/(23)\\.\\d+",
729
+ "os_replacement": "iOS",
730
+ "os_v1_replacement": "17"
731
+ },
732
+ {
733
+ "regex": "CFNetwork/.{0,100} Darwin/24\\.([0-5])\\.\\d+",
734
+ "os_replacement": "iOS",
735
+ "os_v1_replacement": "18",
736
+ "os_v2_replacement": "$1"
737
+ },
738
+ {
739
+ "regex": "CFNetwork/.{0,100} Darwin/(24)\\.\\d+",
740
+ "os_replacement": "iOS",
741
+ "os_v1_replacement": "18"
742
+ },
682
743
  {
683
744
  "regex": "CFNetwork/.{0,100} Darwin/",
684
745
  "os_replacement": "iOS"
@@ -849,10 +910,6 @@
849
910
  {
850
911
  "regex": "(WebTV)/(\\d+).(\\d+)"
851
912
  },
852
- {
853
- "regex": "(CrKey)(?:[/](\\d+)\\.(\\d+)(?:\\.(\\d+)|)|)",
854
- "os_replacement": "Chromecast"
855
- },
856
913
  {
857
914
  "regex": "(hpw|web)OS/(\\d+)\\.(\\d+)(?:\\.(\\d+)|)",
858
915
  "os_replacement": "webOS"
@@ -901,5 +958,15 @@
901
958
  },
902
959
  {
903
960
  "regex": "^(Roku)/DVP-(\\d+)\\.(\\d+)"
961
+ },
962
+ {
963
+ "regex": "os\\/macos[#]?(\\d*)[.]?(\\d*)[.]?(\\d*)",
964
+ "os_replacement": "Mac OS X",
965
+ "os_v1_replacement": "$1",
966
+ "os_v2_replacement": "$2",
967
+ "os_v3_replacement": "$3"
968
+ },
969
+ {
970
+ "regex": "(HarmonyOS)[\\s;]+(\\d+|)\\.?(\\d+|)\\.?(\\d+|)"
904
971
  }
905
972
  ]
package/src/useragent.js CHANGED
@@ -418,15 +418,14 @@ exports.Agent = Agent;
418
418
  * @returns {Boolean}
419
419
  */
420
420
  function isSafe(userAgent) {
421
- let consecutive = 0,
422
- code = 0;
421
+ let consecutive = 0;
423
422
 
424
423
  if (userAgent.length > 1000) {
425
424
  return false;
426
425
  }
427
426
 
428
427
  for (let i = 0; i < userAgent.length; i++) {
429
- code = userAgent.charCodeAt(i);
428
+ const code = userAgent.charCodeAt(i);
430
429
  if (
431
430
  (code >= 48 && code <= 57) || // numbers
432
431
  (code >= 65 && code <= 90) || // letters A-Z
package/.eslintrc.json DELETED
@@ -1,75 +0,0 @@
1
- {
2
- "env": {
3
- "node": true,
4
- "es6": true
5
- },
6
- "plugins": ["node", "import"],
7
- "extends": [
8
- "eslint:recommended",
9
- "plugin:node/recommended",
10
- "plugin:import/recommended"
11
- ],
12
- "rules": {
13
- // -------------------
14
- // Relaxing some rules
15
- // -------------------
16
-
17
- "no-console": "off",
18
- "no-process-exit": "off",
19
-
20
- // ----------------------------------
21
- // Adding more eslint rules as errors
22
- // ----------------------------------
23
-
24
- // Disallow Unused Variables
25
- // https://eslint.org/docs/rules/no-unused-vars
26
- "no-unused-vars": ["error", { "vars": "all" }],
27
- // require using arrow functions as callbacks
28
- // https://eslint.org/docs/rules/prefer-arrow-callback
29
- "prefer-arrow-callback": "error",
30
- // require using template literals instead of string concatenation
31
- // http://eslint.org/docs/rules/prefer-template
32
- "prefer-template": "error",
33
- // require using of const declaration for variables that are never modified after declared
34
- // https://eslint.org/docs/rules/prefer-const
35
- "prefer-const": "error",
36
- // disallow modifying variables that are declared using const
37
- // https://eslint.org/docs/rules/no-const-assign
38
- "no-const-assign": "error",
39
- // require let or const instead of var
40
- // https://eslint.org/docs/rules/no-var
41
- "no-var": "error",
42
-
43
- // ------------------------------------
44
- // Adding more eslint rules as warnings
45
- // ------------------------------------
46
-
47
- // require at least one whitespace after comments( // and /*)
48
- // https://eslint.org/docs/rules/spaced-comment
49
- "spaced-comment": ["warn", "always"],
50
- // Require Following Curly Brace Conventions
51
- // https://eslint.org/docs/rules/curly
52
- "curly": ["warn", "all"],
53
- // Require empty lines after class members
54
- // https://eslint.org/docs/rules/lines-between-class-members
55
- "lines-between-class-members": [
56
- "warn",
57
- "always",
58
- { "exceptAfterSingleLine": true }
59
- ],
60
-
61
- "import/order": [
62
- "warn",
63
- {
64
- "alphabetize": {
65
- "order": "asc",
66
- "caseInsensitive": true
67
- },
68
- "newlines-between": "always"
69
- }
70
- ]
71
- },
72
- "parserOptions": {
73
- "ecmaVersion": 2018
74
- }
75
- }
package/.prettierrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- singleQuote: true,
3
- trailingComma: "es5"
4
- }
@@ -1,38 +0,0 @@
1
- {
2
- "opencollective-2020-11": {
3
- "total": 1525,
4
- "hyperwatch": {
5
- "average": 0.0123,
6
- "miss": 14,
7
- "missPercentage": 0.92
8
- },
9
- "uap": {
10
- "average": 0.0745,
11
- "miss": 40,
12
- "missPercentage": 2.6
13
- },
14
- "combined": {
15
- "average": 0.0196,
16
- "miss": 0,
17
- "missPercentage": 0
18
- }
19
- },
20
- "opencollective-2022-10-14": {
21
- "total": 2558,
22
- "hyperwatch": {
23
- "average": 0.0142,
24
- "miss": 71,
25
- "missPercentage": 2.8
26
- },
27
- "uap": {
28
- "average": 0.0692,
29
- "miss": 111,
30
- "missPercentage": 4.3
31
- },
32
- "combined": {
33
- "average": 0.0206,
34
- "miss": 10,
35
- "missPercentage": 0.39
36
- }
37
- }
38
- }
package/docs/API.md DELETED
@@ -1,178 +0,0 @@
1
- # API
2
-
3
- Include the `@hyperwatch/useragent` parser in you node.js application:
4
-
5
- ```js
6
- const useragent = require('@hyperwatch/useragent');
7
- ```
8
-
9
- ### useragent.parse(useragent string);
10
-
11
- This is the actual user agent parser, this is where all the magic is happening.
12
- The function accepts 1 argument, the user agent string that is known on the server
13
- from the `req.headers.useragent` header.
14
-
15
- The parser returns an `Agent` instance, this allows you to output user agent
16
- information in different predefined formats. See the Agent section for more
17
- information.
18
-
19
- ```js
20
- const agent = useragent.parse(req.headers['user-agent']);
21
- ```
22
-
23
- The parse method returns an `Agent` instance that contains all details about the
24
- user agent. See the Agent section of the API documentation for the available
25
- methods.
26
-
27
- ### useragent.fromJSON(obj);
28
-
29
- Transforms the JSON representation of an `Agent` instance back in to a working
30
- `Agent` instance
31
-
32
- ```js
33
- const agent = useragent.parse(req.headers['user-agent']),
34
- another = useragent.fromJSON(JSON.stringify(agent));
35
-
36
- console.log(agent == another);
37
- ```
38
-
39
- ---
40
-
41
- ## Agent, Os, and Device instances
42
-
43
- Most of the methods mentioned above return an `Agent` instance. The Agent exposes
44
- the parsed out information from the user agent strings. This allows us to
45
- extend the agent with more methods that do not necessarily need to be in the
46
- core agent instance, allowing us to expose a plugin interface for third-party
47
- developers and at the same time create a uniform interface for all versioning.
48
-
49
- The Agent has the following property
50
-
51
- - `family` The browser family, or browser name, defaults to `null`.
52
- - `major` The major version number of the family, defaults to `null`.
53
- - `minor` The minor version number of the family, defaults to `null`.
54
- - `patch` The patch version number of the family, defaults to `null`.
55
- - `patch_minor` The patch version number of the family, defaults to `null`.
56
-
57
- In addition to the properties mentioned above, it also has 2 special properties,
58
- which are:
59
-
60
- - `os` Os instance
61
- - `device` Device instance
62
-
63
- When you access those 2 properties the agent will do on-demand parsing of the
64
- Operating System or/and Device information.
65
-
66
- The Os has the same properties as the Agent, for the Device we
67
- don't have any versioning information available, so only the `family` property is
68
- set there. If we cannot find the family, they will default to `null`.
69
-
70
- The following methods are available:
71
-
72
- ### Agent.toAgent();
73
-
74
- Returns the family and version number concatenated in a nice human-readable
75
- string.
76
-
77
- ```js
78
- const agent = useragent.parse(req.headers['user-agent']);
79
- agent.toAgent(); // 'Firefox 82.0'
80
- ```
81
-
82
- ### Agent.toString();
83
-
84
- Returns the results of the `Agent.toAgent()` but also adds the parsed operating
85
- system to the string in a human-readable format.
86
-
87
- ```js
88
- const agent = useragent.parse(req.headers['user-agent']);
89
- agent.toString(); // 'Firefox 82.0 / Mac OS X 10.15'
90
-
91
- // as it's a to string method you can also concatenate it with another string
92
- 'your useragent is ' + agent;
93
- // 'your useragent is Firefox 82.0 / Mac OS X 10.15'
94
- ```
95
-
96
- ### Agent.toVersion();
97
-
98
- Returns the version of the browser in a human-readable string.
99
-
100
- ```js
101
- const agent = useragent.parse(req.headers['user-agent']);
102
- agent.toVersion(); // '82.0'
103
- ```
104
-
105
- ### Agent.toJSON();
106
-
107
- Generates a JSON representation of the Agent. By using the `toJSON` method we
108
- automatically allow it to be stringified when supplying as to the
109
- `JSON.stringify` method.
110
-
111
- ```js
112
- const agent = useragent.parse(req.headers['user-agent']);
113
- agent.toJSON(); // returns an object
114
-
115
- JSON.stringify(agent);
116
- ```
117
-
118
- ### Os.toString();
119
-
120
- Generates a stringified version of `os`;
121
-
122
- ```js
123
- const agent = useragent.parse(req.headers['user-agent']);
124
- agent.os.toString(); // 'Mac OS X 10.15'
125
- ```
126
-
127
- ### Os.toVersion();
128
-
129
- Generates a stringified version of `os`'s version;
130
-
131
- ```js
132
- const agent = useragent.parse(req.headers['user-agent']);
133
- agent.os.toVersion(); // '10.15'
134
- ```
135
-
136
- ### Os.toJSON();
137
-
138
- Generates a JSON representation of the Os (Operating System). By using the `toJSON`
139
- method we automatically allow it to be stringified when supplying as to the
140
- `JSON.stringify` method.
141
-
142
- ```js
143
- const agent = useragent.parse(req.headers['user-agent']);
144
- agent.os.toJSON(); // returns an object
145
-
146
- JSON.stringify(agent.os);
147
- ```
148
-
149
- ### Device.toString();
150
-
151
- Generates a stringified version of `device`;
152
-
153
- ```js
154
- const agent = useragent.parse(req.headers['user-agent']);
155
- agent.device.toString(); // 'Asus A100'
156
- ```
157
-
158
- ### Device.toVersion();
159
-
160
- Generates a stringified version of the `device`'s version;
161
-
162
- ```js
163
- const agent = useragent.parse(req.headers['user-agent']);
164
- agent.device.toVersion(); // '' , no version found but could also be '0.0.0'
165
- ```
166
-
167
- ### Device.toJSON();
168
-
169
- Generates a JSON representation of the Device. By using the `toJSON` method we
170
- automatically allow it to be stringified when supplying as to the
171
- `JSON.stringify` method.
172
-
173
- ```js
174
- const agent = useragent.parse(req.headers['user-agent']);
175
- agent.device.toJSON(); // returns an object
176
-
177
- JSON.stringify(agent.device);
178
- ```