mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
Merge branch 'develop' of github.com:faisalman/ua-parser-js
This commit is contained in:
commit
b490110109
52
readme.md
52
readme.md
@ -19,17 +19,60 @@ JavaScript library to detect Browser, Engine, OS, CPU, and Device type/model fro
|
|||||||
* Source : https://github.com/faisalman/ua-parser-js
|
* Source : https://github.com/faisalman/ua-parser-js
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
|
### UAParser([user-agent][,extensions])
|
||||||
|
typeof `user-agent` "string".
|
||||||
|
|
||||||
|
typeof `extensions` "array".
|
||||||
|
|
||||||
|
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"]`.
|
||||||
|
|
||||||
|
|
||||||
## Constructor
|
## Constructor
|
||||||
|
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.
|
||||||
|
Like so:
|
||||||
* `new UAParser([uastring][,extensions])`
|
* `new UAParser([uastring][,extensions])`
|
||||||
* returns new instance
|
```js
|
||||||
|
let parser = new UAParser("user-agent"); // you need to pass the user-agent for nodejs
|
||||||
|
console.log(parser); // {}
|
||||||
|
let parserResults = parser.getResults();
|
||||||
|
console.log(parserResults);
|
||||||
|
/** {
|
||||||
|
"ua": "",
|
||||||
|
"browser": {},
|
||||||
|
"engine": {},
|
||||||
|
"os": {},
|
||||||
|
"device": {},
|
||||||
|
"cpu": {}
|
||||||
|
} */
|
||||||
|
```
|
||||||
|
|
||||||
|
When you call UAParser without the `new` keyword, it will automatically call `getResults()` function and return the parsed results.
|
||||||
* `UAParser([uastring][,extensions])`
|
* `UAParser([uastring][,extensions])`
|
||||||
* returns result object `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
|
* returns result object `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
|
#### Methods table
|
||||||
|
The methods are self explanatory, here's a small overview on all the available methods:
|
||||||
|
* `getResult()` - returns all function object calls, user-agent string, browser info, cpu, device, engine, os:
|
||||||
|
`{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`.
|
||||||
|
|
||||||
|
* `getBrowser()` - returns the browser name and version.
|
||||||
|
* `getDevice()` - returns the device model, type, vendor.
|
||||||
|
* `getEngine()` - returns the current browser engine name and version.
|
||||||
|
* `getOS()` - returns the running operating system name and version.
|
||||||
|
* `getCPU()` - returns CPU architectural design name.
|
||||||
|
* `getUA()` - returns the user-agent string.
|
||||||
|
* `setUA(user-agent)` - set a custom user-agent to be parsed.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
* `getResult()`
|
||||||
|
* returns `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
|
||||||
|
|
||||||
* `getBrowser()`
|
* `getBrowser()`
|
||||||
* returns `{ name: '', version: '' }`
|
* returns `{ name: '', version: '' }`
|
||||||
|
|
||||||
@ -114,9 +157,6 @@ VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
|
|||||||
68k, amd64, arm[64/hf], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]
|
68k, amd64, arm[64/hf], avr, ia[32/64], irix[64], mips[64], pa-risc, ppc, sparc[64]
|
||||||
```
|
```
|
||||||
|
|
||||||
* `getResult()`
|
|
||||||
* returns `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
|
|
||||||
|
|
||||||
* `getUA()`
|
* `getUA()`
|
||||||
* returns UA string of current instance
|
* returns UA string of current instance
|
||||||
|
|
||||||
@ -200,6 +240,8 @@ VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
|
|||||||
|
|
||||||
## Using node.js
|
## Using node.js
|
||||||
|
|
||||||
|
Note: Device information is not available in the NodeJS environment.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ npm install ua-parser-js
|
$ npm install ua-parser-js
|
||||||
```
|
```
|
||||||
|
@ -373,7 +373,7 @@
|
|||||||
/////////////////////////
|
/////////////////////////
|
||||||
|
|
||||||
// Samsung
|
// Samsung
|
||||||
/\b(sch-i[89]0\d|shw-m380s|sm-[pt]\w{2,4}|gt-[pn]\d{2,4}|sgh-t8[56]9|nexus 10)/i
|
/\b(sch-i[89]0\d|shw-m380s|sm-[ptx]\w{2,4}|gt-[pn]\d{2,4}|sgh-t8[56]9|nexus 10)/i
|
||||||
], [MODEL, [VENDOR, SAMSUNG], [TYPE, TABLET]], [
|
], [MODEL, [VENDOR, SAMSUNG], [TYPE, TABLET]], [
|
||||||
/\b((?:s[cgp]h|gt|sm)-\w+|galaxy nexus)/i,
|
/\b((?:s[cgp]h|gt|sm)-\w+|galaxy nexus)/i,
|
||||||
/samsung[- ]([-\w]+)/i,
|
/samsung[- ]([-\w]+)/i,
|
||||||
|
@ -1638,6 +1638,15 @@
|
|||||||
"type": "tablet"
|
"type": "tablet"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"desc": "Samsung Galaxy Tab S8",
|
||||||
|
"ua": "Mozilla/5.0 (Linux; Android 12; SM-X706B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36",
|
||||||
|
"expect": {
|
||||||
|
"vendor": "Samsung",
|
||||||
|
"model": "SM-X706B",
|
||||||
|
"type": "tablet"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"desc": "Samsung Galaxy Tab S",
|
"desc": "Samsung Galaxy Tab S",
|
||||||
"ua": "Mozilla/5.0 (Linux; Android 4.4.2; SM-T700 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.135 Safari/537.36",
|
"ua": "Mozilla/5.0 (Linux; Android 4.4.2; SM-T700 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.135 Safari/537.36",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user