super-device-detect is a precise user agent parser and device detector written in TypeScript, backed by the largest and most up-to-date open-source user agent database.
This is a javascript port of Matomo device-detector (4.2.3).
- No dependencies
- TypeScript support
- Thoroughly tested
- New iphone version
To use super-device-detect in your project, run:
npm install super-device-detect
import DeviceDetector from "super-device-detect";
import DeviceDetector = require("super-device-detect");
Example - user agent detection:
import DeviceDetector from "super-device-detect";
const deviceDetector = new DeviceDetector();
const userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36";
const device = deviceDetector.parse(userAgent);
console.log(device);
Output:
{
"client": {
"type": "browser",
"name": "Chrome",
"version": "69.0",
"engine": "Blink",
"engineVersion": ""
},
"os": {
"name": "Mac",
"version": "10.13",
"platform": ""
},
"device": {
"type": "desktop",
"brand": "Apple",
"model": ""
},
"bot": null
}
Example - bot detection:
import BotDetector from "super-device-detect/dist/parsers/bot";
const botDetector = new BotDetector();
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 bot = botDetector.parse(userAgent);
if (bot) {
console.log(bot);
}
Output:
{
"name": "Googlebot",
"category": "Search bot",
"url": "http://www.google.com/bot.html",
"producer": {
"name": "Google Inc.",
"url": "http://www.google.com"
}
}
-
options
<[Object]> Options object which might have the following properties:-
skipBotDetection
<[boolean]> If true, bot detection will completely be skipped (bots will be detected as regular devices). Defaults tofalse
. -
versionTruncation
<[0 | 1 | 2 | 3 | null]> Passingnull
disables version truncation, so full versions will be returned. Defaults to1
, only minor versions will be returned (e.g. X.Y).
-
Type definitions are included in this library and exposed via:
import { DeviceDetectorResult, DeviceDetectorOptions } from "super-device-detect";
This is a free/libre library under license LGPL v3 or later.