Socket
Socket
Sign inDemoInstall

useragent

Package Overview
Dependencies
0
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.1.2

2

package.json
{
"name": "useragent",
"version": "0.1.1",
"version": "0.1.2",
"description": "User-Agent string parser based on Browserscope.org algorithms for more browser reporting",

@@ -5,0 +5,0 @@ "author": "Arnout Kazemier",

@@ -6,3 +6,3 @@ var fs = require('fs'),

fs.readFile( './useragents/user_agent_data.csv', function( err, result ){
if( err )

@@ -12,3 +12,3 @@ return sys.puts( "can't locate file" );

// split file in single rows
var results = result.split( "\n" ), i = results.length,
var results = result.toString().split( "\n" ), i = results.length,
// start times

@@ -21,2 +21,13 @@ total, start = ( new Date() ).valueOf(), failed = [];

//Check all values are filled in correctly
for (var key in agent) {
if (agent[ key ] == undefined) {
failed[ failed.length ] = Array.prototype.concat.call( arguments, [] ).join(",");
sys.puts( JSON.stringify( agent ) );
sys.puts( "Undefined: " + key);
sys.puts( ua + "\n");
break;
}
}
/*if( !agent || !agent.pretty() || !agent.match ){

@@ -32,3 +43,3 @@ failed[ failed.length ] = Array.prototype.concat.call( arguments, [] ).join(",");

// report
// report
if( failed.length ){

@@ -39,4 +50,4 @@ sys.puts( "Failed " + failed.length + " out of " + results.length + " tests." );

}
sys.puts( "Executed in " + (( new Date()).valueOf() - start) + " ms");
});

@@ -6,3 +6,3 @@ var fs = require('fs'),

fs.readFile( './useragents/user_agent_data.csv', function( err, result ){
if( err )

@@ -12,3 +12,3 @@ return sys.puts( "can't locate file" );

// split file in single rows
var results = result.split( "\n" ), i = results.length,
var results = result.toString().split( "\n" ), i = results.length,
// start times

@@ -31,3 +31,3 @@ total, start = ( new Date() ).valueOf(), failed = [];

// report
// report
if( failed.length ){

@@ -38,4 +38,4 @@ sys.puts( "Failed " + failed.length + " out of " + results.length + " tests." );

}
sys.puts( "Executed in " + (( new Date()).valueOf() - start) + " ms");
});

@@ -6,14 +6,14 @@ // low level user agent parsing, usefull for the most and common use cases

ua = ua.toLowerCase();
// inspired by the jQuery browser sniff
return {
version: ( ua.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [ 0, "0" ] )[1],
webkit: ua.indexOf( "webkit" ) !== -1,
opera: ua.indexOf( "opera" ) !== -1,
ie: ua.indexOf( "msie" ) !== -1 && !this.opera,
firefox: ua.indexOf( "mozilla" ) !== -1 && ! ( this.webkit || ua.indexOf( "compatible" ) !== -1 ),
chrome: ua.indexOf( "chrome" ) !== -1 && this.webkit,
safari: ua.indexOf( "safari") !== -1 && !this.chrome,
mobile_safari: ua.indexOf( "apple" ) !== -1 && ua.indexOf( "mobile" ) !== -1 && this.safari
}
var result = {};
result.version = ( ua.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [ 0, "0" ] )[1];
result.webkit = ua.indexOf( "webkit" ) !== -1;
result.opera = ua.indexOf( "opera" ) !== -1;
result.ie = ua.indexOf( "msie" ) !== -1 && !result.opera;
result.firefox = ua.indexOf( "mozilla" ) !== -1 && ! ( result.webkit || ua.indexOf( "compatible" ) !== -1 );
result.chrome = ua.indexOf( "chrome" ) !== -1 && result.webkit;
result.safari = ua.indexOf( "safari") !== -1 && !result.chrome;
result.mobile_safari = ua.indexOf( "apple" ) !== -1 && ua.indexOf( "mobile" ) !== -1 && result.safari;
return result;
};

@@ -25,3 +25,3 @@

os, ua_obj, sequence;
// check we can parse down the ua based the parse object

@@ -31,6 +31,6 @@ function parse( parser_obj ){

match;
// check if we have positive match
match = parser_obj.regexp.exec( ua );
if( match ){

@@ -43,5 +43,5 @@ // check if we need to replace some items

family = parser_obj.family_replacement;
} else
} else
family = match[1];
// check for which version information is available

@@ -52,3 +52,3 @@ if( parser_obj.V1_replacement )

V1 = match[2];
if( match.length >= 3 ){

@@ -60,4 +60,4 @@ V2 = match[3];

}
// return the parse results

@@ -72,3 +72,3 @@ return {

};
// create a pretty user agent string from the ua object

@@ -79,3 +79,3 @@ function pretty( user_agent, os ){

format = "$0";
// generate a pretty output format

@@ -87,3 +87,3 @@ if( ua.V1 ){

if( ua.V3 ){
// check if its a digit or not,
// check if its a digit or not,
if( !isNaN( ua.V3 ) )

@@ -96,7 +96,7 @@ format = format + ".$3";

}
// operating system
if( ua.os && os )
format = format + " / $4";
// replace placeholder with actual content

@@ -109,7 +109,7 @@ return format.replace( "$0", ua.family )

};
// the actual finding of the correct user agent group.
for( ; i < length; i++ ){
ua_obj = parse( browsers[i] );
// no need to continue parsing other sequence

@@ -119,3 +119,3 @@ if( ua_obj.match )

}
// are we working with a chrome frame perhaps?

@@ -151,3 +151,3 @@ if( js_ua && ua.indexOf( "chromeframe" ) != -1 )

// doing a .join("|") because its easier to maintain as array,
// if you want raw perfomance, compile this a string.
// if you want raw perfomance, compile this a string.
var browser_slash_v123_names = [

@@ -196,3 +196,3 @@ "Jasmine",

].join( "|" ),
browser_slash_v12_names = [

@@ -239,3 +239,3 @@ "Bolt",

].join( "|" ),
// the parser regexp storage, this will be used by the UA parser

@@ -246,3 +246,3 @@ browsers = [

{ regexp: /^(Opera)\/(\d+)\.(\d+) \(Nintendo Wii/, family_replacement:"Wii" },
// must go before browser v1.v2

@@ -265,10 +265,10 @@ // eg: Minefield/3.1a1pre

{ regexp:/(Fennec)\/(\d+)\.(\d+)(pre)/ },
{ regexp:/(Firefox)\/(\d+)\.(\d+)\.(\d+(?:pre)?) \(Swiftfox\)/, family_replacement:"Swiftfox" },
{ regexp:/(Firefox)\/(\d+)\.(\d+)([ab]\d+[a-z]*)? \(Swiftfox\)/, family_replacement:"Swiftfox" },
// lowercase konqueror
{ regexp:/(konqueror)\/(\d+)\.(\d+)\.(\d+)/, family_replacement:"Konqueror" },
// MAIN CASES, this will match about 50% of the browsers

@@ -287,3 +287,3 @@ // browsers with v123

{ regexp:/(Firefox)\/(\d+)\.(\d+)(pre|[ab]\d+[a-z]*)?/ },
// SPECIAL CASES

@@ -290,0 +290,0 @@ { regexp:/(Obigo|OBIGO)[^\d]*(\d+)(?:.(\d+))?/, family_replacement:"Obigo" },

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc