Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
node-device-detector
Advanced tools
Last update: 19/02/2022
Port php lib matomo-org/device-detector to NodeJs
npm install node-device-detector --save
or
yarn add node-device-detector
const DeviceDetector = require('node-device-detector');
const detector = new DeviceDetector;
const userAgent = 'Mozilla/5.0 (Linux; Android 5.0; NX505J Build/KVT49L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.78 Mobile Safari/537.36';
const result = detector.detect(userAgent);
console.log('result parse', result);
PS: When creating an object
detector = new DeviceDetector;
data for parsing is reloaded from files, consider this, the best option is initialization at application start I recommend seeing examples
{
os: {
name: 'Android', // os name
short_name: 'AND', // os short code name (format A-Z0-9{3})
version: '5.0', // os version
platform: '', // os platform (x64, x32, amd etc.)
family: 'Android' // os family
},
client: {
type: 'browser', // client type
name: 'Chrome Mobile', // client name name
short_name: 'CM', // client short code name (only browser, format A-Z0-9{2})
version: '43.0.2357.78', // client version
engine: 'Blink', // client engine name (only browser)
engine_version: '' // client engine version (only browser)
family: 'Chrome' // client family (only browser)
},
device: {
id: 'ZT', // short code device brand name (format A-Z0-9{2,3})
type: 'smartphone', // device type
brand: 'ZTE', // device brand name
model: 'Nubia Z7 max' // device model name
}
}
Result parse empty
{
os: {}, // empty objects its os not found
client: {}, // empty objects its client not found
device: {
id: '', // empty string its device brand not found
type : 'device type', // device type or empty string
brand: '', // empty string its device brand not found
model: '' // empty string its device model not found
}
}
const DeviceDetector = require('node-device-detector');
const DeviceHelper = require('node-device-detector/helper');
const detector = new DeviceDetector;
const userAgent = 'Mozilla/5.0 (Linux; Android 5.0; NX505J Build/KVT49L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.78 Mobile Safari/537.36';
const result = detector.detect(userAgent);
/* check device type (feature phone, smartphone or phablet) */
DeviceHelper.isMobile(result);
/* check device type is desktop */
DeviceHelper.isDesktop(result);
/* check device type is tablet */
DeviceHelper.isTablet(result);
/* check device type car (side panel in car) */
DeviceHelper.isCar(result);
/* check device type feature phone (push-button telephones) */
DeviceHelper.isFeaturePhone(result);
/* check device type smartphone */
DeviceHelper.isSmartphone(result);
/* check device type phablet */
DeviceHelper.isPhablet(result);
/* check device type game console (xBox, PlayStation, Nintendo etc) */
DeviceHelper.isConsole(result);
/* check device type smart speaker (Alisa, Alexa, HomePod etc) */
DeviceHelper.isSmartSpeaker(result);
/* check device type SmartTV/TV box */
DeviceHelper.isTv(result);
/* check device type portable camera */
DeviceHelper.isCamera(result);
/* portable terminal, portable projector */
DeviceHelper.isPeripheral(result);
/* LCD panel or interactive panel */
DeviceHelper.isSmartDisplay(result);
/* check device type boxes, blu-ray players */
DeviceHelper.isPortableMediaPlayer(result);
/* check device type watches, headsets */
DeviceHelper.isWearable(result);
/* result device type number id */
DeviceHelper.getDeviceTypeId(result);
/* result device type string */
DeviceHelper.getDeviceType(result);
/* result client type string */
DeviceHelper.getClientType(result);
const DeviceDetector = require('node-device-detector');
const userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)';
const detector = new DeviceDetector();
const result = detector.parseBot(userAgent);
const DeviceDetector = require('node-device-detector');
const userAgent = 'Mozilla/5.0 (Linux; Android 5.0; NX505J Build/KVT49L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.78 Mobile Safari/537.36';
const detector = new DeviceDetector;
const result = detector.parseOs(userAgent);
console.log('Result parse os', result);
const DeviceDetector = require('node-device-detector');
const userAgent = 'Mozilla/5.0 (Linux; Android 5.0; NX505J Build/KVT49L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.78 Mobile Safari/537.36';
const detector = new DeviceDetector;
const result = detector.parseClient(userAgent);
console.log('Result parse client', result);
const DeviceDetector = require('node-device-detector');
const userAgent = 'Mozilla/5.0 (Linux; Android 5.0; NX505J Build/KVT49L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.78 Mobile Safari/537.36';
const detector = new DeviceDetector;
const resultOs = detector.parseOs(userAgent);
const resultClient = detector.parseClient(userAgent);
const resultDeviceType = detector.parseDeviceType(userAgent, resultOs, resultClient, {});
const result = Object.assign({os:resultOs}, {client:resultClient}, {device: resultDeviceType});
console.log('Result parse lite', result);
const detector = new DeviceDetector({
osVersionTruncate: 0, // Truncate Os version from 5.0 to 5 (default '' or null)
clientVersionTruncate: 2, // Truncate Client version Chrome from 43.0.2357 .78 to 43.0.2357 (default '' or null)
discardDeviceIndexes: false, // quick device definitions using indexing (disabled by default, set value false to enable),
filePathDeviceIndexes: null // custom index file path
});
// format file filePathDeviceIndexes
// You can override these settings at any time using special methods, example
detector.setOsVersionTruncate(0);
detector.setClientVersionTruncate(2);
detector.discardDeviceIndexes = false;
/**
banchmark.js test result:
----
Test: Mozilla/5.0 (Linux; Android 7.1.2; E6810) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.76 Mobile Safari/537.36
EnableDeviceIndexes x 1,184 ops/sec ±0.52% (92 runs sampled)
DiscardDeviceIndexes x 636 ops/sec ±0.44% (94 runs sampled)
----
Test: Mozilla/5.0 (Linux; Android 5.0; NX505J Build/KVT49L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.78 Mobile Safari/537.36
EnableDeviceIndexes x 1,148 ops/sec ±0.49% (93 runs sampled)
DiscardDeviceIndexes x 404 ops/sec ±0.38% (92 runs sampled)
----
Test: Mozilla/5.0 (Linux; Android 4.4.4; Qin 1s+ Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36
EnableDeviceIndexes x 1,022 ops/sec ±0.43% (92 runs sampled)
DiscardDeviceIndexes x 395 ops/sec ±0.31% (90 runs sampled)
*/
// Array available device types
detector.getAvailableDeviceTypes();
// Array available devices brands
detector.getAvailableBrands();
// Array available browsers
detector.getAvailableBrowsers();
const AliasDevice = require('node-device-detector/parser/device/alias-device');
const userAgent = 'Mozilla/5.0 (Linux; Android 5.0; NX505J Build/KVT49L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.78 Mobile Safari/537.36';
const aliasDevice = new AliasDevice;
const result = aliasDevice.parse(userAgent);
console.log('Result parse code model', result);
/*
result
{
name: "NX505J"
}
is not parse result {name: ""}
*/
This parser is experimental and contains few devices. (1692 devices, alias devices 3707)
Brand | Device count | Alias count | - | Brand | Device count | Alias count |
---|---|---|---|---|---|---|
360 | 10 | 10 | - | 8848 | 2 | 0 |
2e | 2 | 2 | - | 3gnet | 0 | 1 |
3q | 14 | 62 | - | 4good | 10 | 1 |
4ife | 0 | 1 | - | a1 | 0 | 1 |
accent | 0 | 5 | - | ace | 8 | 0 |
acer | 5 | 68 | - | acteck | 0 | 0 |
advan | 0 | 1 | - | advance | 0 | 14 |
afrione | 0 | 2 | - | agm | 4 | 0 |
ainol | 0 | 16 | - | airness | 0 | 0 |
airo wireless | 1 | 0 | - | airties | 0 | 0 |
ais | 0 | 2 | - | aiuto | 0 | 0 |
aiwa | 0 | 0 | - | akai | 2 | 5 |
alba | 0 | 1 | - | alcatel | 29 | 433 |
alcor | 1 | 0 | - | alfawise | 0 | 0 |
aligator | 0 | 0 | - | allcall | 0 | 3 |
alldocube | 2 | 6 | - | allview | 0 | 46 |
allwinner | 0 | 3 | - | altech uec | 0 | 0 |
altek | 1 | 0 | - | altice | 0 | 0 |
altron | 0 | 1 | - | amazon | 19 | 30 |
amgoo | 2 | 15 | - | amigoo | 0 | 0 |
amoi | 62 | 2 | - | andowl | 0 | 0 |
anry | 0 | 0 | - | ans | 0 | 0 |
aoc | 0 | 0 | - | aoson | 0 | 6 |
apple | 46 | 44 | - | archos | 89 | 7 |
arian space | 4 | 2 | - | ark | 1 | 36 |
armphone | 0 | 0 | - | arnova | 0 | 36 |
arris | 0 | 0 | - | artel | 0 | 2 |
artizlee | 0 | 1 | - | asano | 0 | 1 |
asanzo | 1 | 0 | - | ask | 0 | 0 |
assistant | 2 | 19 | - | asus | 81 | 230 |
at&t | 1 | 2 | - | atom | 0 | 3 |
atvio | 0 | 0 | - | avenzo | 1 | 3 |
avh | 1 | 0 | - | avvio | 3 | 2 |
axxion | 0 | 0 | - | azumi mobile | 0 | 1 |
bangolufsen | 0 | 0 | - | barnes & noble | 1 | 6 |
bb mobile | 2 | 10 | - | beeline | 11 | 1 |
bellphone | 1 | 1 | - | benq | 0 | 1 |
beyond | 0 | 7 | - | bezkam | 1 | 0 |
bigben | 1 | 0 | - | bihee | 2 | 1 |
billion | 1 | 1 | - | bird | 1 | 0 |
bitel | 4 | 1 | - | bitmore | 2 | 1 |
bkav | 1 | 0 | - | black bear | 2 | 0 |
black fox | 18 | 12 | - | blackview | 15 | 9 |
blu | 1 | 1 | - | bravis | 24 | 17 |
clarmin | 3 | 0 | - | colors | 7 | 2 |
digifors | 1 | 1 | - | engel | 1 | 1 |
firefly mobile | 4 | 1 | - | formuler | 2 | 0 |
geotel | 3 | 0 | - | gionee | 4 | 0 |
3 | 5 | - | hisense | 2 | 0 | |
hotwav | 18 | 1 | - | huawei | 226 | 586 |
imo mobile | 5 | 0 | - | inoi | 4 | 0 |
intex | 9 | 3 | - | ipro | 6 | 7 |
irbis | 15 | 0 | - | kurio | 3 | 3 |
lg | 127 | 286 | - | maze | 4 | 0 |
minix | 1 | 1 | - | mivo | 3 | 2 |
mobicel | 3 | 1 | - | motorola | 27 | 24 |
noa | 1 | 0 | - | nuu mobile | 9 | 3 |
nuvo | 3 | 2 | - | oneplus | 18 | 48 |
oppo | 84 | 169 | - | oukitel | 8 | 0 |
öwn | 1 | 2 | - | panasonic | 5 | 8 |
pipo | 5 | 0 | - | realme | 65 | 94 |
samsung | 167 | 714 | - | sony | 44 | 172 |
supra | 1 | 0 | - | tecno mobile | 79 | 113 |
tiphone | 1 | 0 | - | utok | 1 | 0 |
uz mobile | 1 | 0 | - | vernee | 9 | 2 |
vivo | 173 | 243 | - | walton | 13 | 0 |
we | 8 | 0 | - | weimei | 1 | 0 |
wiko | 6 | 5 | - | wileyfox | 9 | 0 |
wink | 4 | 0 | - | zync | 2 | 0 |
zyq | 1 | 13 | - |
const InfoDevice = require('node-device-detector/parser/device/info-device');
const infoDevice = new InfoDevice;
const result = infoDevice.info('Asus', 'Zenfone 4');
console.log('Result information', result);
/*
result
{
display: {
size: '5.5',
resolution: '1080x1920', // width+height
ratio: '16:9',
ppi: "401"
},
size: '155.4x75.2x7.7', // width+height+thickness
weight: '165',
hardware: {
// ...
}
os: "Android 7.1",
release: "2017.08",
sim": "2",
}
is not found result null
*/
Cast methods
const InfoDevice = require('node-device-detector/parser/device/info-device');
const infoDevice = new InfoDevice;
infoDevice.setSizeConvertObject(true);
infoDevice.setResolutionConvertObject(true);
const result = infoDevice.info('Asus', 'Zenfone 4');
console.log('Result information', result);
/*
result
{
display: {
size: "5.5", // value in inchs
resolution: {
width: "1080", // value in px
height: "1920" // value in px
},
ratio: "16:9", // calculated field
ppi: "401" // calculated field
},
hardware: {
ram: "4096", // RAM value in megabytes
cpu_id: 19, // id cpu model in collection
cpu: {
name: "Qualcomm Snapdragon 630", // brand + name
type: "ARM", // architecture type
cores: "8", // number of cores / threads
clock_rate: 2200, // value in MHz
gpu_id: 16 // id gpu model in collection
},
gpu: {
name: "Qualcomm Adreno 508",
clock_rate: 650
}
},
os: "Android 7.1", // initial OS version
release: "2017.08", // date release or anonce
sim": "2", // count SIM
size: {
width: "75.2", // physical width in millimeters
height: "155.4", // physical height in millimeters
thickness: "7.7" // physical thickness in millimeters
},
weight: "165" // in grams
};
*/
type | id |
---|---|
desktop | 0 |
smartphone | 1 |
tablet | 2 |
feature phone | 3 |
console | 4 |
tv | 5 |
car browser | 6 |
smart display | 7 |
camera | 8 |
portable media player | 9 |
phablet | 10 |
smart speaker | 11 |
wearable | 12 |
peripheral | 13 |
FAQs
Nodejs device detector (port matomo-org/device-detector)
The npm package node-device-detector receives a total of 12,830 weekly downloads. As such, node-device-detector popularity was classified as popular.
We found that node-device-detector demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.