Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

user-agent-parse

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

user-agent-parse - npm Package Compare versions

Comparing version 0.1.8 to 0.1.10

.travis.yml

237

lib/user-agent-parse.js
/*!
* user-agent-parse
* user-agent-parse
* heavily based *ahem* on https://github.com/soldair/node-ua-device-type and https://github.com/jujhars13/node-user-agent-parse

@@ -27,11 +27,11 @@ * to produce an output like PHP's get_browser http://php.net/manual/en/function.get-browser.php

*/
exports.parse = function(str) {
var agent = {};
agent.full = str;
agent.name = name(str);
agent.version = version(str, agent.name);
agent.fullName = agent.name + ' ' + agent.version;
agent.os = os(str);
agent.device_type = getDeviceType(str);
return agent;
exports.parse = function (str) {
var agent = {};
agent.full = str;
agent.name = name(str);
agent.version = version(str, agent.name);
agent.fullName = agent.name + ' ' + agent.version;
agent.os = os(str);
agent.device_type = getDeviceType(str);
return agent;
};

@@ -47,11 +47,10 @@

*/
function version(str, name) {
if (name === 'safari')
name = 'version';
if (name) {
return new RegExp(name + '[\\/ ]([\\d\\w\\.-]+)', 'i').exec(str) && RegExp.$1 || '';
} else {
var m = str.match(/version[\/ ]([\d\w\.]+)/i);
return m && m.length > 1 ? m[1] : '';
}
function version (str, name) {
if (name === 'safari') { name = 'version'; }
if (name) {
return new RegExp(name + '[\\/ ]([\\d\\w\\.-]+)', 'i').exec(str) && RegExp.$1 || '';
} else {
var m = str.match(/version[\/ ]([\d\w\.]+)/i);
return m && m.length > 1 ? m[1] : '';
}
}

@@ -62,16 +61,18 @@

*/
var operatingSystems = {
'iPad': /ipad/i
, 'iPhone': /iphone/i
, 'Windows Vista': /windows nt 6\.0/i
, 'Windows 7 or 8': /windows nt 6\.\d+/i
, 'Windows 2003': /windows nt 5\.2+/i
, 'Windows XP': /windows nt 5\.1+/i
, 'Windows 2000': /windows nt 5\.0+/i
, 'OS X $1.$2': /os x (\d+)[._](\d+)/i
, 'Linux': /linux/i
, 'Googlebot': /googlebot/i
const operatingSystems = {
'iPad': /ipad/i,
'iPhone': /iphone/i,
'Android': /android/i,
'Windows 10': /windows nt 10\.0/i,
'Windows 7 or 8': /windows nt 6\.\d+/i,
'Windows Vista': /windows nt 6\.0/i,
'Windows 2003': /windows nt 5\.2+/i,
'Windows XP': /windows nt 5\.1+/i,
'Windows 2000': /windows nt 5\.0+/i,
'OS X $1.$2': /os x (\d+)[._](\d+)/i,
'Linux': /linux/i,
'Googlebot': /googlebot/i
};
var osNames = Object.keys(operatingSystems);
const osNames = Object.keys(operatingSystems);

@@ -85,13 +86,13 @@ /**

*/
function os(str) {
var captures;
for (var i = 0, len = osNames.length; i < len; ++i) {
if (captures = operatingSystems[osNames[i]].exec(str)) {
return ~osNames[i].indexOf('$1')
? osNames[i].replace(/\$(\d+)/g, function(_, n) {
return captures[n]
}) : osNames[i];
}
function os (str) {
var captures;
for (var i = 0, len = osNames.length; i < len; ++i) {
if (captures = operatingSystems[osNames[i]].exec(str)) {
return ~osNames[i].indexOf('$1')
? osNames[i].replace(/\$(\d+)/g, function (_, n) {
return captures[n];
}) : osNames[i];
}
return '';
}
return '';
}

@@ -103,11 +104,11 @@

var names = [
'opera',
'konqueror',
'firefox',
'chrome',
'epiphany',
'safari',
'msie',
'curl',
'maxthon'
'opera',
'konqueror',
'firefox',
'chrome',
'epiphany',
'safari',
'msie',
'curl',
'maxthon'
];

@@ -122,12 +123,10 @@

*/
function name(str) {
str = str.toLowerCase();
for (var i = 0, len = names.length; i < len; ++i) {
if (str.indexOf(names[i]) !== -1)
return names[i];
}
return '';
function name (str) {
str = str.toLowerCase();
for (var i = 0, len = names.length; i < len; ++i) {
if (str.indexOf(names[i]) !== -1) { return names[i]; }
}
return '';
}
/**

@@ -137,5 +136,5 @@ * Default options for getDeviceType

var defaultOptions = {
emptyUserAgentDeviceType: 'desktop',
unknownUserAgentDeviceType: 'phone',
botUserAgentDeviceType: 'bot'
emptyUserAgentDeviceType: 'desktop',
unknownUserAgentDeviceType: 'phone',
botUserAgentDeviceType: 'bot'
};

@@ -147,7 +146,7 @@

var devices = {
tv: "tv",
tablet: "tablet",
phone: "phone",
desktop: "desktop",
bot: "bot"
tv: 'tv',
tablet: 'tablet',
phone: 'phone',
desktop: 'desktop',
bot: 'bot'
};

@@ -160,56 +159,56 @@

*/
function getDeviceType(ua) {
options = defaultOptions || {};
function getDeviceType (ua) {
options = defaultOptions || {};
if (!ua || ua === '') {
// No user agent.
return options.emptyUserAgentDeviceType || devices.desktop;
}
if (!ua || ua === '') {
// No user agent.
return options.emptyUserAgentDeviceType || devices.desktop;
}
if (ua.match(/GoogleTV|SmartTV|Internet TV|NetCast|NETTV|AppleTV|boxee|Kylo|Roku|DLNADOC|CE\-HTML/i)) {
// if user agent is a smart TV - http://goo.gl/FocDk
return devices.tv;
} else if (ua.match(/Xbox|PLAYSTATION 3|Wii/i)) {
// if user agent is a TV Based Gaming Console
return devices.tv;
} else if (ua.match(/iP(a|ro)d/i) || (ua.match(/tablet/i) && !ua.match(/RX-34/i)) || ua.match(/FOLIO/i)) {
// if user agent is a Tablet
return devices.tablet;
} else if (ua.match(/Linux/i) && ua.match(/Android/i) && !ua.match(/Fennec|mobi|HTC Magic|HTCX06HT|Nexus One|SC-02B|fone 945/i)) {
// if user agent is an Android Tablet
return devices.tablet;
} else if (ua.match(/Kindle/i) || (ua.match(/Mac OS/i) && ua.match(/Silk/i))) {
// if user agent is a Kindle or Kindle Fire
return devices.tablet;
} else if (ua.match(/GT-P10|SC-01C|SHW-M180S|SGH-T849|SCH-I800|SHW-M180L|SPH-P100|SGH-I987|zt180|HTC( Flyer|_Flyer)|Sprint ATP51|ViewPad7|pandigital(sprnova|nova)|Ideos S7|Dell Streak 7|Advent Vega|A101IT|A70BHT|MID7015|Next2|nook/i) || (ua.match(/MB511/i) && ua.match(/RUTEM/i))) {
// if user agent is a pre Android 3.0 Tablet
return devices.tablet;
} else if (ua.match(/BOLT|Fennec|Iris|Maemo|Minimo|Mobi|mowser|NetFront|Novarra|Prism|RX-34|Skyfire|Tear|XV6875|XV6975|Google Wireless Transcoder/i)) {
// if user agent is unique mobile User Agent
return devices.phone;
} else if (ua.match(/Opera/i) && ua.match(/Windows NT 5/i) && ua.match(/HTC|Xda|Mini|Vario|SAMSUNG\-GT\-i8000|SAMSUNG\-SGH\-i9/i)) {
// if user agent is an odd Opera User Agent - http://goo.gl/nK90K
return devices.phone;
} else if ((ua.match(/Windows (NT|XP|ME|9)/) && !ua.match(/Phone/i)) && !ua.match(/Bot|Spider|ia_archiver|NewsGator/i) || ua.match(/Win( ?9|NT)/i)) {
// if user agent is Windows Desktop
return devices.desktop;
} else if (ua.match(/Macintosh|PowerPC/i) && !ua.match(/Silk/i)) {
// if agent is Mac Desktop
return devices.desktop;
} else if (ua.match(/Linux/i) && ua.match(/X11/i) && !ua.match(/Charlotte/i)) {
// if user agent is a Linux Desktop
return devices.desktop;
} else if (ua.match(/CrOS/)) {
// if user agent is a Chrome Book
return devices.desktop;
} else if (ua.match(/Solaris|SunOS|BSD/i)) {
// if user agent is a Solaris, SunOS, BSD Desktop
return devices.desktop;
} else if (ua.match(/curl|Bot|B-O-T|Crawler|Spider|Spyder|Yahoo|ia_archiver|Covario-IDS|findlinks|DataparkSearch|larbin|Mediapartners-Google|NG-Search|Snappy|Teoma|Jeeves|Charlotte|NewsGator|TinEye|Cerberian|SearchSight|Zao|Scrubby|Qseero|PycURL|Pompos|oegp|SBIder|yoogliFetchAgent|yacy|webcollage|VYU2|voyager|updated|truwoGPS|StackRambler|Sqworm|silk|semanticdiscovery|ScoutJet|Nymesis|NetResearchServer|MVAClient|mogimogi|Mnogosearch|Arachmo|Accoona|holmes|htdig|ichiro|webis|LinkWalker|lwp-trivial/i) && !ua.match(/mobile|Playstation/i)) {
// if user agent is a BOT/Crawler/Spider
return options.botUserAgentDeviceType || devices.bot;
} else {
// Otherwise assume it is a mobile Device
return options.unknownUserAgentDeviceType || devices.phone;
}
}
if (ua.match(/GoogleTV|SmartTV|Internet TV|NetCast|NETTV|AppleTV|boxee|Kylo|Roku|DLNADOC|CE\-HTML/i)) {
// if user agent is a smart TV - http://goo.gl/FocDk
return devices.tv;
} else if (ua.match(/Xbox|PLAYSTATION 3|Wii/i)) {
// if user agent is a TV Based Gaming Console
return devices.tv;
} else if (ua.match(/iP(a|ro)d/i) || (ua.match(/tablet/i) && !ua.match(/RX-34/i)) || ua.match(/FOLIO/i)) {
// if user agent is a Tablet
return devices.tablet;
} else if (ua.match(/Linux/i) && ua.match(/Android/i) && !ua.match(/Fennec|mobi|HTC Magic|HTCX06HT|Nexus One|SC-02B|fone 945/i)) {
// if user agent is an Android Tablet
return devices.tablet;
} else if (ua.match(/Kindle/i) || (ua.match(/Mac OS/i) && ua.match(/Silk/i))) {
// if user agent is a Kindle or Kindle Fire
return devices.tablet;
} else if (ua.match(/GT-P10|SC-01C|SHW-M180S|SGH-T849|SCH-I800|SHW-M180L|SPH-P100|SGH-I987|zt180|HTC( Flyer|_Flyer)|Sprint ATP51|ViewPad7|pandigital(sprnova|nova)|Ideos S7|Dell Streak 7|Advent Vega|A101IT|A70BHT|MID7015|Next2|nook/i) || (ua.match(/MB511/i) && ua.match(/RUTEM/i))) {
// if user agent is a pre Android 3.0 Tablet
return devices.tablet;
} else if (ua.match(/BOLT|Fennec|Iris|Maemo|Minimo|Mobi|mowser|NetFront|Novarra|Prism|RX-34|Skyfire|Tear|XV6875|XV6975|Google Wireless Transcoder/i)) {
// if user agent is unique mobile User Agent
return devices.phone;
} else if (ua.match(/Opera/i) && ua.match(/Windows NT 5/i) && ua.match(/HTC|Xda|Mini|Vario|SAMSUNG\-GT\-i8000|SAMSUNG\-SGH\-i9/i)) {
// if user agent is an odd Opera User Agent - http://goo.gl/nK90K
return devices.phone;
} else if ((ua.match(/Windows (NT|XP|ME|9)/) && !ua.match(/Phone/i)) && !ua.match(/Bot|Spider|ia_archiver|NewsGator/i) || ua.match(/Win( ?9|NT)/i)) {
// if user agent is Windows Desktop
return devices.desktop;
} else if (ua.match(/Macintosh|PowerPC/i) && !ua.match(/Silk/i)) {
// if agent is Mac Desktop
return devices.desktop;
} else if (ua.match(/Linux/i) && ua.match(/X11/i) && !ua.match(/Charlotte/i)) {
// if user agent is a Linux Desktop
return devices.desktop;
} else if (ua.match(/CrOS/)) {
// if user agent is a Chrome Book
return devices.desktop;
} else if (ua.match(/Solaris|SunOS|BSD/i)) {
// if user agent is a Solaris, SunOS, BSD Desktop
return devices.desktop;
} else if (ua.match(/curl|Bot|B-O-T|Crawler|Spider|Spyder|Yahoo|ia_archiver|Covario-IDS|findlinks|DataparkSearch|larbin|Mediapartners-Google|NG-Search|Snappy|Teoma|Jeeves|Charlotte|NewsGator|TinEye|Cerberian|SearchSight|Zao|Scrubby|Qseero|PycURL|Pompos|oegp|SBIder|yoogliFetchAgent|yacy|webcollage|VYU2|voyager|updated|truwoGPS|StackRambler|Sqworm|silk|semanticdiscovery|ScoutJet|Nymesis|NetResearchServer|MVAClient|mogimogi|Mnogosearch|Arachmo|Accoona|holmes|htdig|ichiro|webis|LinkWalker|lwp-trivial/i) && !ua.match(/mobile|Playstation/i)) {
// if user agent is a BOT/Crawler/Spider
return options.botUserAgentDeviceType || devices.bot;
} else {
// Otherwise assume it is a mobile Device
return options.unknownUserAgentDeviceType || devices.phone;
}
}
{
"name": "user-agent-parse",
"description": "rudimentary browser user-agent parser",
"version": "0.1.8",
"version": "0.1.10",
"repository": {

@@ -21,3 +21,2 @@ "type": "git",

],
"readme": "# node-user-agent-parse\n\n ## Overview\n\n Parse user agents a bit like PHP's get_browser() http://php.net/manual/en/function.get-browser.php\n\n ## Example\n\n var userAgent = require('user-agent')\n userAgent.parse('Mozilla/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8')\n // => { name: 'safari', version: '4.0dp1', os: 'Windows XP', full: '... same string as above ...', device_type:'desktop' }\n ## Credits\n\n Heavily Based (Blatantly ripped from *ahem*) on https://github.com/soldair/node-ua-device-type and https://github.com/jujhars13/node-user-agent-parse\n\n ## TODO\n\n BDD using vows\n\n ##License\n\n License is MIT, go nuts. That's how we roll here at Buto.\n\n http://opensource.org/licenses/mit-license.php\n\n",
"readmeFilename": "README.md",

@@ -28,8 +27,9 @@ "_id": "user-agent-parse@1.0.5",

"devDependencies": {
"lodash": "~2.2.1",
"should": "~1.3.0",
"mocha": "~1.13.0"
"lodash": "~4.17.15"
},
"scripts":{
"test":"npm run ./test"
},
"optionalDependencies": {},
"license": "BSD"
}
}

@@ -1,8 +0,13 @@

# NodeJs User Agent Parse
# Node User Agent Parse
[![NPM](https://nodei.co/npm/user-agent-parse.png?downloads=true)](https://nodei.co/npm/user-agent-parse/)
## Build Status
[![Build Status](https://travis-ci.org/jujhars13/node-user-agent-parse.png?branch=master)](https://travis-ci.org/jujhars13/node-user-agent-parse)
## Overview
Parse user agents a bit like PHP's [get_browser()](http://php.net/manual/en/function.get-browser.php)
Parse user agents a bit like PHP's [get_browser()](http://php.net/manual/en/function.get-browser.php).
Rudimentary but it works.

@@ -17,10 +22,9 @@ ## Example

Heavily Based (Blatantly ripped from *ahem*) on https://github.com/soldair/node-ua-device-type and https://github.com/jujhars13/node-user-agent-parse
Heavily based on (blatantly ripped from *ahem*) https://github.com/soldair/node-ua-device-type and https://github.com/jujhars13/node-user-agent-parse
## TODO
Test using mocha
Implemnet tests using `mocha` and `should`
##License
License is [MIT](http://opensource.org/licenses/mit-license.php), go nuts. That's how we roll here at [Buto](http://get.buto.tv).
License is [MIT](http://opensource.org/licenses/mit-license.php), go nuts.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc