Skip to content

Commit cb5da5e

Browse files
authored
Merge pull request #600 from moekm/develop
Improved documentation README.md
2 parents 8d21e34 + b2d685d commit cb5da5e

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

readme.md

+55-6
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,60 @@ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model fro
1919
* Source : https://github.com/faisalman/ua-parser-js
2020

2121
# Documentation
22+
### UAParser([user-agent][,extensions])
23+
typeof `user-agent` "string".
24+
25+
typeof `extensions` "array".
26+
27+
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.
28+
Usually you can find the user agent in:
29+
`request.headers["user-agent"]`.
2230

23-
## Constructor
2431

32+
## Constructor
33+
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.
34+
Like so:
2535
* `new UAParser([uastring][,extensions])`
26-
* returns new instance
36+
```js
37+
let parser = new UAParser("user-agent"); // you need to pass the user-agent for nodejs
38+
console.log(parser); // {}
39+
let parserResults = parser.getResults();
40+
console.log(parserResults);
41+
/** {
42+
"ua": "",
43+
"browser": {},
44+
"engine": {},
45+
"os": {},
46+
"device": {},
47+
"cpu": {}
48+
} */
49+
```
2750

51+
When you call UAParser without the `new` keyword, it will automatically call `getResults()` function and return the parsed results.
2852
* `UAParser([uastring][,extensions])`
2953
* returns result object `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
3054

3155
## Methods
3256

57+
#### Methods table
58+
The methods are self explanatory, here's a small overview on all the available methods:
59+
* `getResult()` - returns all function object calls, user-agent string, browser info, cpu, device, engine, os:
60+
`{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`.
61+
62+
* `getBrowser()` - returns the browser name and version.
63+
* `getDevice()` - returns the device model, type, vendor.
64+
* `getEngine()` - returns the current browser engine name and version.
65+
* `getOS()` - returns the running operating system name and version.
66+
* `getCPU()` - returns CPU architectural design name.
67+
* `getUA()` - returns the user-agent string.
68+
* `setUA(user-agent)` - set a custom user-agent to be parsed.
69+
70+
71+
---
72+
73+
* `getResult()`
74+
* returns `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
75+
3376
* `getBrowser()`
3477
* returns `{ name: '', version: '' }`
3578

@@ -39,7 +82,7 @@ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model fro
3982
BIDUBrowser, Baidu, Basilisk, Blazer, Bolt, Brave, Bowser, Camino, Chimera,
4083
Chrome Headless, Chrome WebView, Chrome, Chromium, Comodo Dragon, Dillo,
4184
Dolphin, Doris, DuckDuckGo, Edge, Electron, Epiphany, Facebook, Falkon, Fennec,
42-
Firebird, Firefox [Reality], Flock, Flow, GSA, GoBrowser, Huawei Browser,
85+
Firebird, Firefox [Focus/Reality], Flock, Flow, GSA, GoBrowser, Huawei Browser,
4386
ICE Browser, IE, IEMobile, IceApe, IceCat, IceDragon, Iceweasel, Instagram,
4487
Iridium, Iron, Jasmine, K-Meleon, Kindle, Klar, Konqueror, LBBROWSER, Line,
4588
LinkedIn, Links, Lunascape, Lynx, MIUI Browser, Maemo Browser, Maemo, Maxthon,
@@ -61,6 +104,13 @@ Yandex, baidu, iCab, w3m, Whale Browser...
61104
# Possible 'device.type':
62105
console, mobile, tablet, smarttv, wearable, embedded
63106

107+
##########
108+
# NOTE: 'desktop' is not a possible device type.
109+
# UAParser only reports info directly available from the UA string, which is not the case for 'desktop' device type.
110+
# If you wish to detect desktop devices, you must handle the needed logic yourself.
111+
# You can read more about it in this issue: https://github.com/faisalman/ua-parser-js/issues/182
112+
##########
113+
64114
# Possible 'device.vendor':
65115
Acer, Alcatel, Amazon, Apple, Archos, ASUS, AT&T, BenQ, BlackBerry, Dell,
66116
Essential, Fairphone, GeeksPhone, Google, HP, HTC, Huawei, Jolla, Lenovo, LG,
@@ -107,9 +157,6 @@ VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
107157
68k, amd64, arm[64/hf], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]
108158
```
109159

110-
* `getResult()`
111-
* returns `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
112-
113160
* `getUA()`
114161
* returns UA string of current instance
115162

@@ -193,6 +240,8 @@ VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
193240

194241
## Using node.js
195242

243+
Note: Device information is not available in the NodeJS environment.
244+
196245
```sh
197246
$ npm install ua-parser-js
198247
```

0 commit comments

Comments
 (0)