Skip to content

Instantly share code, notes, and snippets.

@evanpurkhiser
Created February 24, 2023 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanpurkhiser/9e293d962dd3764439f38a6e51a8aab4 to your computer and use it in GitHub Desktop.
Save evanpurkhiser/9e293d962dd3764439f38a6e51a8aab4 to your computer and use it in GitHub Desktop.
Only in ua-parser-0.7: .github
Only in ua-parser-0.7: .travis.yml
Only in ua-parser-0.7: bower.json
Common subdirectories: ua-parser-0.7/dist and ua-parser-1.0.33/dist
Only in ua-parser-0.7: package.js
diff --unified ua-parser-0.7/package.json ua-parser-1.0.33/package.json
--- ua-parser-0.7/package.json 2023-02-24 13:58:01
+++ ua-parser-1.0.33/package.json 2023-02-24 13:58:22
@@ -1,9 +1,9 @@
{
"title": "UAParser.js",
"name": "ua-parser-js",
- "version": "0.7.28",
+ "version": "1.0.33",
"author": "Faisal Salman <f@faisalman.com> (http://faisalman.com)",
- "description": "Lightweight JavaScript-based user-agent string parser",
+ "description": "Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data. Supports browser & node.js environment",
"keywords": [
"user-agent",
"parser",
@@ -141,8 +141,12 @@
"Zach Bjornson <zbbjornson@gmail.com>"
],
"main": "src/ua-parser.js",
+ "files": [
+ "dist",
+ "src"
+ ],
"scripts": {
- "build": "uglifyjs src/ua-parser.js -o dist/ua-parser.min.js --comments && uglifyjs src/ua-parser.js -o dist/ua-parser.pack.js --comments --compress --mangle",
+ "build": "uglifyjs src/ua-parser.js -o dist/ua-parser.min.js --comments '/^ UA/' && uglifyjs src/ua-parser.js -o dist/ua-parser.pack.js --comments '/^ UA/' --compress --mangle",
"test": "jshint src/ua-parser.js && mocha -R nyan test/test.js",
"test-ci": "jshint src/ua-parser.js && mocha -R spec test/test.js",
"verup": "node ./node_modules/verup",
@@ -156,10 +160,12 @@
],
"regs": [
"^((?:\\$|(\\s*\\*\\s*@)|(\\s*(?:var|,)?\\s+))(?:LIBVERSION|version)[\\s\\:='\"]+)([0-9]+(?:\\.[0-9]+){2,2})",
- "^(\\s?\\*.*v)([0-9]+(?:\\.[0-9]+){2,2})"
+ "^(\\/?\\s?\\*.*v)([0-9]+(?:\\.[0-9]+){2,2})"
]
},
"devDependencies": {
+ "@babel/parser": "7.15.8",
+ "@babel/traverse": "7.15.4",
"jshint": "~2.12.0",
"mocha": "~8.2.0",
"requirejs": "^2.3.2",
diff --unified ua-parser-0.7/readme.md ua-parser-1.0.33/readme.md
--- ua-parser-0.7/readme.md 2023-02-24 13:58:01
+++ ua-parser-1.0.33/readme.md 2023-02-24 13:58:22
@@ -15,21 +15,64 @@
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).
* Author : Faisal Salman <<f@faisalman.com>>
-* Demo : http://faisalman.github.io/ua-parser-js
+* Demo : https://faisalman.github.io/ua-parser-js
* Source : https://github.com/faisalman/ua-parser-js
# Documentation
+### UAParser([user-agent][,extensions])
+typeof `user-agent` "string".
-## Constructor
+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
+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])`
- * 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.getResult();
+console.log(parserResults);
+/** {
+ "ua": "",
+ "browser": {},
+ "engine": {},
+ "os": {},
+ "device": {},
+ "cpu": {}
+} */
+```
+When you call UAParser without the `new` keyword, it will automatically call `getResult()` function and return the parsed results.
* `UAParser([uastring][,extensions])`
* returns result object `{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }`
## 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()`
* returns `{ name: '', version: '' }`
@@ -38,17 +81,18 @@
2345Explorer, 360 Browser, Amaya, Android Browser, Arora, Avant, Avast, AVG,
BIDUBrowser, Baidu, Basilisk, Blazer, Bolt, Brave, Bowser, Camino, Chimera,
Chrome Headless, Chrome WebView, Chrome, Chromium, Comodo Dragon, Dillo,
-Dolphin, Doris, Edge, Electron, Epiphany, Facebook, Falkon, Fennec, Firebird,
-Firefox [Reality], Flock, Flow, GSA, GoBrowser, ICE Browser, IE, IEMobile, IceApe,
-IceCat, IceDragon, Iceweasel, Instagram, Iridium, Iron, Jasmine, K-Meleon,
-Kindle, Konqueror, LBBROWSER, Line, Links, Lunascape, Lynx, MIUI Browser,
-Maemo Browser, Maemo, Maxthon, MetaSr Midori, Minimo, Mobile Safari, Mosaic,
-Mozilla, NetFront, NetSurf, Netfront, Netscape, NokiaBrowser, Oculus Browser,
-OmniWeb, Opera Coast, Opera [Mini/Mobi/Tablet], PaleMoon, PhantomJS, Phoenix,
-Polaris, Puffin, QQ, QQBrowser, QQBrowserLite, Quark, QupZilla, RockMelt, Safari,
-Sailfish Browser, Samsung Browser, SeaMonkey, Silk, Skyfire, Sleipnir, Slim,
-SlimBrowser, Swiftfox, Tesla, Tizen Browser, UCBrowser, Vivaldi, Waterfox, WeChat,
-Weibo, Yandex, baidu, iCab, w3m, Whale Browser...
+Dolphin, Doris, DuckDuckGo, Edge, Electron, Epiphany, Facebook, Falkon, Fennec,
+Firebird, Firefox [Focus/Reality], Flock, Flow, GSA, GoBrowser, Huawei Browser,
+ICE Browser, IE, IEMobile, IceApe, IceCat, IceDragon, Iceweasel, Instagram,
+Iridium, Iron, Jasmine, K-Meleon, Kindle, Klar, Konqueror, LBBROWSER, Line,
+LinkedIn, Links, Lunascape, Lynx, MIUI Browser, Maemo Browser, Maemo, Maxthon,
+MetaSr Midori, Minimo, Mobile Safari, Mosaic, Mozilla, NetFront, NetSurf, Netfront,
+Netscape, NokiaBrowser, Obigo, Oculus Browser, OmniWeb, Opera Coast,
+Opera [Mini/Mobi/Tablet], PaleMoon, PhantomJS, Phoenix, Polaris, Puffin, QQ,
+QQBrowser, QQBrowserLite, Quark, QupZilla, RockMelt, Safari, Sailfish Browser,
+Samsung Browser, SeaMonkey, Silk, Skyfire, Sleipnir, Slim, SlimBrowser, Swiftfox,
+Tesla, Tizen Browser, UCBrowser, UP.Browser, Vivaldi, Waterfox, WeChat, Weibo,
+Yandex, baidu, iCab, w3m, Whale Browser...
# 'browser.version' determined dynamically
```
@@ -60,11 +104,18 @@
# Possible 'device.type':
console, mobile, tablet, smarttv, wearable, embedded
+##########
+# NOTE: 'desktop' is not a possible device type.
+# UAParser only reports info directly available from the UA string, which is not the case for 'desktop' device type.
+# If you wish to detect desktop devices, you must handle the needed logic yourself.
+# You can read more about it in this issue: https://github.com/faisalman/ua-parser-js/issues/182
+##########
+
# Possible 'device.vendor':
Acer, Alcatel, Amazon, Apple, Archos, ASUS, AT&T, BenQ, BlackBerry, Dell,
Essential, Fairphone, GeeksPhone, Google, HP, HTC, Huawei, Jolla, Lenovo, LG,
Meizu, Microsoft, Motorola, Nexian, Nintendo, Nokia, Nvidia, OnePlus, OPPO, Ouya,
-Palm, Panasonic, Pebble, Polytron, Realme, RIM, Samsung, Sharp, Siemens,
+Palm, Panasonic, Pebble, Polytron, Realme, RIM, Roku, Samsung, Sharp, Siemens,
Sony[Ericsson], Sprint, Tesla, Vivo, Vodafone, Xbox, Xiaomi, Zebra, ZTE, ...
# 'device.model' determined dynamically
@@ -86,11 +137,12 @@
```sh
# Possible 'os.name'
-AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
-Contiki, Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Fuchsia, Gentoo, GNU,
-Haiku, Hurd, iOS, Joli, KaiOS, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo,
-Minix, Mint, Morph OS, NetBSD, Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD,
-PCLinuxOS, Plan9, PlayStation, QNX, Raspbian, RedHat, RIM Tablet OS, RISC OS,
+AIX, Amiga OS, Android[-x86], Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,
+Contiki, Fedora, Firefox OS, FreeBSD, Debian, Deepin, DragonFly, elementary OS,
+Fuchsia, Gentoo, GhostBSD, GNU, Haiku, HarmonyOS, HP-UX, Hurd, iOS, Joli, KaiOS,
+Linpus, Linspire,Linux, Mac OS, Maemo, Mageia, Mandriva, Manjaro, MeeGo, Minix,
+Mint, Morph OS, NetBSD, Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PC-BSD, PCLinuxOS,
+Plan9, PlayStation, QNX, Raspbian, RedHat, RIM Tablet OS, RISC OS, Sabayon,
Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen, Ubuntu, Unix,
VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk, ...
@@ -105,9 +157,6 @@
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()`
* returns UA string of current instance
@@ -190,6 +239,8 @@
```
## Using node.js
+
+Note: Device information is not available in the NodeJS environment.
```sh
$ npm install ua-parser-js
Common subdirectories: ua-parser-0.7/src and ua-parser-1.0.33/src
Only in ua-parser-0.7: test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment