Gathering detailed insights and metrics for @streamrail/ua-parser-js
Gathering detailed insights and metrics for @streamrail/ua-parser-js
Gathering detailed insights and metrics for @streamrail/ua-parser-js
Gathering detailed insights and metrics for @streamrail/ua-parser-js
npm install @streamrail/ua-parser-js
Typescript
Module System
Min. Node Version
Node Version
NPM Version
75.6
Supply Chain
99.5
Quality
82.8
Maintenance
100
Vulnerability
80.9
License
JavaScript (98.85%)
TypeScript (0.75%)
Shell (0.41%)
Total Downloads
4,075
Last Day
2
Last Week
6
Last Month
40
Last Year
460
9,377 Stars
1,209 Commits
1,198 Forks
129 Watching
10 Branches
135 Contributors
Latest Version
3.0.0
Package Id
@streamrail/ua-parser-js@3.0.0
Unpacked Size
158.46 kB
Size
28.73 kB
File Count
17
NPM Version
5.6.0
Node Version
8.9.4
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
0%
6
Compared to previous week
Last month
90.5%
40
Compared to previous month
Last year
-16.4%
460
Compared to previous year
Lightweight JavaScript-based User-Agent string parser. Supports browser & node.js environment. Also available as jQuery/Zepto plugin, Component/Bower/Meteor package, & RequireJS/AMD module
Extract detailed type of web browser, layout engine, operating system, cpu architecture, and device type/model purely from user-agent string with relatively lightweight footprint (~11KB minified / ~4KB gzipped). Written in vanilla js, which means it doesn't depends on any other library.
getBrowser()
{ name: '', major: '', version: '' }
# Possible 'browser.name':
Amaya, Android Browser, Arora, Avant, Baidu, Blazer, Bolt, Camino, Chimera, Chrome,
Chromium, Comodo Dragon, Conkeror, Dillo, Dolphin, Doris, Edge, Epiphany, Fennec,
Firebird, Firefox, Flock, GoBrowser, iCab, ICE Browser, IceApe, IceCat, IceDragon,
Iceweasel, IE [Mobile], Iron, Jasmine, K-Meleon, Konqueror, Kindle, Links,
Lunascape, Lynx, Maemo, Maxthon, Midori, Minimo, MIUI Browser, [Mobile] Safari,
Mosaic, Mozilla, Netfront, Netscape, NetSurf, Nokia, OmniWeb, Opera [Mini/Mobi/Tablet],
Phoenix, Polaris, QQBrowser, RockMelt, Silk, Skyfire, SeaMonkey, SlimBrowser, Swiftfox,
Tizen, UCBrowser, Vivaldi, w3m, Yandex
# 'browser.version' determined dynamically
getDevice()
{ model: '', type: '', vendor: '' }
# Possible 'device.type':
console, mobile, tablet, smarttv, wearable, embedded
# Possible 'device.vendor':
Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, GeeksPhone,
Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola, Nexian,
Nintendo, Nokia, Nvidia, Ouya, Palm, Panasonic, Polytron, RIM, Samsung, Sharp,
Siemens, Sony-Ericsson, Sprint, Xbox, ZTE
# 'device.model' determined dynamically
getEngine()
{ name: '', version: '' }
# Possible 'engine.name'
Amaya, EdgeHTML, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto,
Tasman, Trident, w3m, WebKit
# 'engine.version' determined dynamically
getOS()
{ name: '', version: '' }
# Possible 'os.name'
AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS, Contiki,
Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Gentoo, GNU, Haiku, Hurd, iOS,
Joli, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo, Minix, Mint, Morph OS, NetBSD,
Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PCLinuxOS, Plan9, Playstation, QNX, RedHat,
RIM Tablet OS, RISC OS, Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen,
Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk
# 'os.version' determined dynamically
getCPU()
{ architecture: '' }
# Possible 'cpu.architecture'
68k, amd64, arm, arm64, avr, ia32, ia64, irix, irix64, mips, mips64, pa-risc,
ppc, sparc, sparc64
getResult()
{ ua: '', browser: {}, cpu: {}, device: {}, engine: {}, os: {} }
getUA()
setUA(uastring)
1<!doctype html> 2<html> 3<head> 4<script type="text/javascript" src="ua-parser.min.js"></script> 5<script type="text/javascript"> 6 7 var parser = new UAParser(); 8 9 // by default it takes ua string from current browser's window.navigator.userAgent 10 console.log(parser.getResult()); 11 /* 12 /// this will print an object structured like this: 13 { 14 ua: "", 15 browser: { 16 name: "", 17 version: "" 18 }, 19 engine: { 20 name: "", 21 version: "" 22 }, 23 os: { 24 name: "", 25 version: "" 26 }, 27 device: { 28 model: "", 29 type: "", 30 vendor: "" 31 }, 32 cpu: { 33 architecture: "" 34 } 35 } 36 */ 37 38 // let's test a custom user-agent string as an example 39 var uastring = "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"; 40 parser.setUA(uastring); 41 42 var result = parser.getResult(); 43 // this will also produce the same result (without instantiation): 44 // var result = UAParser(uastring); 45 46 console.log(result.browser); // {name: "Chromium", version: "15.0.874.106"} 47 console.log(result.device); // {model: undefined, type: undefined, vendor: undefined} 48 console.log(result.os); // {name: "Ubuntu", version: "11.10"} 49 console.log(result.os.version); // "11.10" 50 console.log(result.engine.name); // "WebKit" 51 console.log(result.cpu.architecture); // "amd64" 52 53 // do some other tests 54 var uastring2 = "Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)"; 55 console.log(parser.setUA(uastring2).getBrowser().name); // "Konqueror" 56 console.log(parser.getOS()); // {name: "OpenBSD", version: undefined} 57 console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"} 58 59 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'; 60 console.log(parser.setUA(uastring3).getDevice().model); // "PlayBook" 61 console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"} 62 console.log(parser.getBrowser().name); // "Safari" 63 64</script> 65</head> 66<body> 67</body> 68</html>
1$ npm install ua-parser-js
1var UAParser = require('ua-parser-js'); 2var parser = new UAParser(); 3var ua = request.headers['user-agent']; // user-agent header from an HTTP request 4console.log(parser.setUA(ua).getResult());
1require(['ua-parser'], function(UAParser) { 2 var parser = new UAParser(); 3 console.log(parser.getResult()); 4});
1$ component install faisalman/ua-parser-js
1var UAParser = require('ua-parser-js'); 2var parser = new UAParser(); 3console.log(parser.getResult());
1$ bower install ua-parser-js
1$ meteor add faisalman:ua-parser-js
Although written in vanilla js (which means it doesn't depends on jQuery), this library will automatically detect if jQuery/Zepto is present and create $.ua
object based on browser's user-agent (although in case you need, window.UAParser
constructor is still present). To get/set user-agent you can use: $.ua.get()
/ $.ua.set(uastring)
.
1// In browser with default user-agent: 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0': 2 3// Do some tests 4console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"} 5console.log($.ua.os); // {name: "Android", version: "2.3.4"} 6console.log($.ua.os.name); // "Android" 7console.log($.ua.get()); // "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0" 8 9// reset to custom user-agent 10$.ua.set('Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; Xoom Build/HWI69) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'); 11 12// Test again 13console.log($.ua.browser.name); // "Safari" 14console.log($.ua.engine.name); // "Webkit" 15console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"} 16console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
UAParser(uastring[, extensions])
Pass your own regexes to extend the limited matching rules.
1// Example: 2var uaString = 'ownbrowser/1.3'; 3var ownBrowser = [[/(ownbrowser)\/((\d+)?[\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION, UAParser.BROWSER.MAJOR]]; 4var parser = new UAParser(uaString, {browser: ownBrowser}); 5console.log(parser.getBrowser()); // {name: "ownbrowser", major: "1", version: "1.3"}
Verify, test, & minify script
1$ npm run test 2$ npm run build
Then submit a pull request to https://github.com/faisalman/ua-parser-js under develop
branch.
Dual licensed under GPLv2 & MIT
Copyright © 2012-2015 Faisal Salman <fyzlman@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
14 different organizations found -- score normalized to 10
Details
Reason
no dangerous workflow patterns detected
Reason
update tool detected
Details
Reason
project is fuzzed with [OSSFuzz]
Reason
license file detected
Details
Reason
11 commit(s) out of 30 and 4 issue activity out of 30 found in the last 90 days -- score normalized to 10
Reason
publishing workflow detected
Details
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 9
Details
Reason
non read-only tokens detected in GitHub workflows
Details
Reason
4 out of 5 merged PRs checked by a CI test -- score normalized to 8
Reason
SAST tool detected but not run on all commmits
Details
Reason
badge detected: passing
Reason
branch protection is not maximal on development and all release branches
Details
Reason
5 out of last 30 changesets reviewed before merge -- score normalized to 1
Score
Last Scanned on 2024-03-19
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More