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

device

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

device - npm Package Compare versions

Comparing version 0.3.8 to 0.3.9

15

lib/device.js

@@ -12,2 +12,4 @@ /* Based on Categorizr (https://github.com/bjankord/Categorizr) by Brett Jankord (http://www.brettjankord.com) */

carUserAgentDeviceType: 'car',
consoleUserAgentDeviceType: 'tv',
tvUserAgentDeviceType: 'tv',
parseUserAgent: false

@@ -54,6 +56,6 @@ };

// if user agent is a smart TV - http://goo.gl/FocDk
return 'tv';
return self.options.tvUserAgentDeviceType;
} else if (ua.match(/Xbox|PLAYSTATION (3|4)|Wii/i)) {
// if user agent is a TV Based Gaming Console
return 'tv';
return self.options.consoleUserAgentDeviceType;
} else if (ua.match(/QtCarBrowser/i)) {

@@ -65,2 +67,5 @@ // if the user agent is a car

return self.options.botUserAgentDeviceType;
} else if (ua.match(/WhatsApp/i)) {
// if user agent is a BOT/Crawler/Spider
return self.options.botUserAgentDeviceType;
} else if (ua.match(/iP(a|ro)d/i) || (ua.match(/tablet/i) && !ua.match(/RX-34/i)) || ua.match(/FOLIO/i)) {

@@ -87,3 +92,3 @@ // if user agent is a Tablet

return 'desktop';
} else if (ua.match(/Macintosh|PowerPC/i) && !ua.match(/Silk/i)) {
} else if (ua.match(/Macintosh|PowerPC/i) && !ua.match(/Silk|moatbot/i)) {
// if agent is Mac Desktop

@@ -100,7 +105,7 @@ return 'desktop';

return 'desktop';
} else if (ua.match(/Mozilla\/5\.0 \(\)|jack|Applebot|FlipboardProxy|Go 1.1 package|HTMLParser|simplereach|python-requests|ShowyouBot|MetaURI|nineconnections|(^Java\/[0-9._]*)|Commons-HttpClient|InAGist|HTTP-Java-Client|curl|Wget|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|facebookexternalhit|monit\/|ELB-HealthChecker\/|JobBot|GoogleCloudMonitoring/i) && !ua.match(/phone|Playstation/i)) {
} else if (ua.match(/Mozilla\/5\.0 \(\)|jack|Applebot|FlipboardProxy|Go 1.1 package|HTMLParser|simplereach|python-requests|ShowyouBot|MetaURI|nineconnections|(^Java\/[0-9._]*)|Commons-HttpClient|InAGist|HTTP-Java-Client|curl|Wget|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|facebookexternalhit|monit\/|ELB-HealthChecker\/|JobBot|GoogleCloudMonitoring|GoogleStackdriverMonitoring|gomezagent|apm synthetic agent|ruxitsynthetic|ktxn|khte|ktht|dynatrace/i) && !ua.match(/phone|Playstation/i)) {
// if user agent is a BOT/Crawler/Spider
return self.options.botUserAgentDeviceType;
} else {
// Otherwise assume it is a phone Device
// Otherwise returning the unknown type configured
return self.options.unknownUserAgentDeviceType;

@@ -107,0 +112,0 @@ }

@@ -6,3 +6,3 @@ {

"keywords": ["browser","mobile","detection","user-agent","useragent","desktop","phone","tablet","tv","bot","car","parsing","device"],
"version": "0.3.8",
"version": "0.3.9",
"main": "./index.js",

@@ -9,0 +9,0 @@ "private": false,

@@ -46,3 +46,3 @@ # device [![NPM version](http://img.shields.io/npm/v/device.svg?style=flat)](https://npmjs.org/package/device) [![Downloads](https://img.shields.io/npm/dm/device.svg?style=flat)](https://npmjs.org/package/device) [![Build Status](https://secure.travis-ci.org/rguerreiro/device.png?branch=master)](http://travis-ci.org/rguerreiro/device)

<td>Device type to be returned whenever the has an empty user-agent. Defaults to desktop.</td>
<td>desktop, tv, tablet, phone, bot or car</td>
<td>desktop, tv, tablet, phone, bot, car or console</td>
</tr>

@@ -53,3 +53,3 @@ <tr>

<td>Device type to be returned whenever the user-agent is unknown. Defaults to phone.</td>
<td>desktop, tv, tablet, phone, bot or car</td>
<td>desktop, tv, tablet, phone, bot, car or console</td>
</tr>

@@ -60,3 +60,3 @@ <tr>

<td>Device type to be returned whenever the user-agent belongs to a bot. Defaults to bot.</td>
<td>desktop, tv, tablet, phone, bot or car</td>
<td>desktop, tv, tablet, phone, bot, car or console</td>
</tr>

@@ -67,5 +67,17 @@ <tr>

<td>Device type to be returned whenever the user-agent belongs to a car. Defaults to car.</td>
<td>desktop, tv, tablet, phone, bot or car</td>
<td>desktop, tv, tablet, phone, bot, car or console</td>
</tr>
<tr>
<td>consoleUserAgentDeviceType</td>
<td>string</td>
<td>Device type to be returned whenever the user-agent belongs to a console. Defaults to tv.</td>
<td>desktop, tv, tablet, phone, bot, car or console</td>
</tr>
<tr>
<td>tvUserAgentDeviceType</td>
<td>string</td>
<td>Device type to be returned whenever the user-agent belongs to a tv. Defaults to tv.</td>
<td>desktop, tv, tablet, phone, bot, car or console</td>
</tr>
<tr>
<td>parseUserAgent</td>

@@ -80,2 +92,4 @@ <td>string</td>

The **device** package is supported on node version 4.* upwards.
## contributors

@@ -101,2 +115,4 @@

- [@BorePlusPlus](https://github.com/BorePlusPlus)
- [@Minaru](https://github.com/Minaru)
- [@fmmsilva](https://github.com/fmmsilva)

@@ -107,4 +123,6 @@ Special thanks to [@jimmybergman](https://github.com/jimmybergman) that allowed me to use his `device` package for this refactoring.

Currently, `device` is on **version 0.3.8**. In order to add more features I'm asking anyone to contribute with some ideas. You can do it by making some feature requests on the issues panel, but I prefer that you make your contribution with some pull requests ;)
Currently, `device` is on **version 0.3.9**. In order to add more features I'm asking anyone to contribute with some ideas. You can do it by making some feature requests on the issues panel, but I prefer that you make your contribution with some pull requests ;)
In case you found a misinterpreted user-agent please open an issue and submit the full string and state what type of device it should return.
## license

@@ -111,0 +129,0 @@

@@ -474,2 +474,8 @@ var device = require('../lib/device.js'),

});
describe('79.WhatsApp Bot', function () {
it('should get device type bot', function () {
var mydevice = device('*_WhatsApp/2.12.81 (Windows NT 6.1; U; es-ES) Presto/2.9.181 Version/12.00');
assert.equal(mydevice.type, 'bot');
});
});
describe('Bot device type check with is method', function () {

@@ -476,0 +482,0 @@ it('should get true', function () {

@@ -515,2 +515,20 @@ var device = require('../lib/device.js'),

});
describe('85.Chrome 63.0.3239.132 on Win 10 Pro', function () {
it('should get true', function () {
var mydevice = device('User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36');
assert.equal(mydevice.is('desktop'), true);
});
});
describe('86.Firefox 57.0.4 on Win 10 Pro', function () {
it('should get true', function () {
var mydevice = device('User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36');
assert.equal(mydevice.is('desktop'), true);
});
});
describe('87.Edge 41.16299.15.0 on Win 10 Pro', function () {
it('should get true', function () {
var mydevice = device('User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.48 Safari/537.36');
assert.equal(mydevice.is('desktop'), true);
});
});
});

@@ -1001,2 +1001,8 @@ var device = require('../lib/device.js'),

});
describe('iPad Pro 12.9', function () {
it('should get device type tablet', function () {
var mydevice = device('Mozilla/5.0 (iPad; CPU OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Version/10.0 Mobile/14C89 Safari/602.1');
assert.equal(mydevice.is('tablet'), true);
});
});
});

@@ -47,2 +47,16 @@ var device = require('../lib/device.js'),

describe('unknown user-agent configured to return car',function(){
it('should get car', function(){
var mydevice = device('dsfglkfjawflkehf', { unknownUserAgentDeviceType: 'car' });
assert.equal(mydevice.type, 'car');
});
});
describe('unknown user-agent configured to return console',function(){
it('should get console', function(){
var mydevice = device('dsfglkfjawflkehf', { unknownUserAgentDeviceType: 'console' });
assert.equal(mydevice.type, 'console');
});
});
describe('with no user-agent',function(){

@@ -97,2 +111,23 @@ it('should get desktop', function(){

describe('with no user-agent and configured to return car',function(){
it('should get car', function(){
var mydevice = device(null, { emptyUserAgentDeviceType: 'car' });
assert.equal(mydevice.type, 'car');
});
});
describe('with no user-agent and configured to return console',function(){
it('should get console', function(){
var mydevice = device(null, { emptyUserAgentDeviceType: 'console' });
assert.equal(mydevice.type, 'console');
});
});
describe('with bot user agent', function(){
it('should get bot', function(){
var mydevice = device('Bot', { botUserAgentDeviceType: 'bot' });
assert.equal(mydevice.type, 'bot');
})
});
describe('with bot user agent and configured to return desktop', function(){

@@ -125,4 +160,25 @@ it('should get desktop', function(){

});
describe('with car user agent and configured to return desktop', function(){
describe('with bot user agent and configured to return car', function(){
it('should get car', function(){
var mydevice = device('Bot', { botUserAgentDeviceType: 'car' });
assert.equal(mydevice.type, 'car');
})
});
describe('with bot user agent and configured to return console', function(){
it('should get console', function(){
var mydevice = device('Bot', { botUserAgentDeviceType: 'console' });
assert.equal(mydevice.type, 'console');
})
});
describe('with car user agent', function(){
it('should get car', function(){
var mydevice = device('QtCarBrowser', { carUserAgentDeviceType: 'car' });
assert.equal(mydevice.type, 'car');
})
});
describe('with car user agent and configured to return desktop', function(){
it('should get desktop', function(){

@@ -155,2 +211,114 @@ var mydevice = device('QtCarBrowser', { carUserAgentDeviceType: 'desktop' });

describe('with car user agent and configured to return console', function(){
it('should get console', function(){
var mydevice = device('QtCarBrowser', { carUserAgentDeviceType: 'console' });
assert.equal(mydevice.type, 'console');
})
});
describe('with car user agent and configured to return bot', function(){
it('should get bot', function(){
var mydevice = device('QtCarBrowser', { carUserAgentDeviceType: 'bot' });
assert.equal(mydevice.type, 'bot');
})
});
describe('with console user agent', function(){
it('should get tv', function(){
var mydevice = device('Mozilla/5.0 (PLAYSTATION 3; 3.55)');
assert.equal(mydevice.type, 'tv');
})
});
describe('with console user agent and configured to return desktop', function(){
it('should get desktop', function(){
var mydevice = device('Mozilla/5.0 (PLAYSTATION 3; 3.55)', { consoleUserAgentDeviceType: 'desktop' });
assert.equal(mydevice.type, 'desktop');
})
});
describe('with console user agent and configured to return tablet', function(){
it('should get tablet', function(){
var mydevice = device('Mozilla/5.0 (PLAYSTATION 3; 3.55)', { consoleUserAgentDeviceType: 'tablet' });
assert.equal(mydevice.type, 'tablet');
})
});
describe('with console user agent and configured to return phone', function(){
it('should get phone', function(){
var mydevice = device('Mozilla/5.0 (PLAYSTATION 3; 3.55)', { consoleUserAgentDeviceType: 'phone' });
assert.equal(mydevice.type, 'phone');
})
});
describe('with console user agent and configured to return car', function(){
it('should get car', function(){
var mydevice = device('Mozilla/5.0 (PLAYSTATION 3; 3.55)', { consoleUserAgentDeviceType: 'car' });
assert.equal(mydevice.type, 'car');
})
});
describe('with console user agent and configured to return bot', function(){
it('should get bot', function(){
var mydevice = device('Mozilla/5.0 (PLAYSTATION 3; 3.55)', { consoleUserAgentDeviceType: 'bot' });
assert.equal(mydevice.type, 'bot');
})
});
describe('with console user agent and configured to return console', function(){
it('should get console', function(){
var mydevice = device('Mozilla/5.0 (PLAYSTATION 3; 3.55)', { consoleUserAgentDeviceType: 'console' });
assert.equal(mydevice.type, 'console');
})
});
describe('with tv user agent', function(){
it('should get tv', function(){
var mydevice = device('iTunes-AppleTV/4.1');
assert.equal(mydevice.type, 'tv');
})
});
describe('with tv user agent and configured to return desktop', function(){
it('should get desktop', function(){
var mydevice = device('iTunes-AppleTV/4.1', { tvUserAgentDeviceType: 'desktop' });
assert.equal(mydevice.type, 'desktop');
})
});
describe('with tv user agent and configured to return tablet', function(){
it('should get tablet', function(){
var mydevice = device('iTunes-AppleTV/4.1', { tvUserAgentDeviceType: 'tablet' });
assert.equal(mydevice.type, 'tablet');
})
});
describe('with tv user agent and configured to return phone', function(){
it('should get phone', function(){
var mydevice = device('iTunes-AppleTV/4.1', { tvUserAgentDeviceType: 'phone' });
assert.equal(mydevice.type, 'phone');
})
});
describe('with tv user agent and configured to return car', function(){
it('should get car', function(){
var mydevice = device('iTunes-AppleTV/4.1', { tvUserAgentDeviceType: 'car' });
assert.equal(mydevice.type, 'car');
})
});
describe('with tv user agent and configured to return bot', function(){
it('should get bot', function(){
var mydevice = device('iTunes-AppleTV/4.1', { tvUserAgentDeviceType: 'bot' });
assert.equal(mydevice.type, 'bot');
})
});
describe('with tv user agent and configured to return console', function(){
it('should get console', function(){
var mydevice = device('iTunes-AppleTV/4.1', { tvUserAgentDeviceType: 'console' });
assert.equal(mydevice.type, 'console');
})
});
describe('with user-agent of google nexus 10 and parse enabled', function () {

@@ -157,0 +325,0 @@ it('should get nexus 10 as device name', function () {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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