Package Exports
- device-detector-js
- device-detector-js/dist/parsers/bot
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (device-detector-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
device-detector-js
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
This is a Node.js port of Matomo device-detector.
Getting Started
Installation
To use device-detector-js in your project, run:
npm install device-detector-jsUsage
Example - simple user agent detection:
const DeviceDetector = require("device-detector-js");
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:
const DeviceDetector = require("device-detector-js");
const deviceDetector = new DeviceDetector();
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 device = deviceDetector.parse(userAgent);
console.log(device.bot);Output:
{
"name": "Googlebot",
"category": "Search bot",
"url": "http://www.google.com/bot.html",
"producer": {
"name": "Google Inc.",
"url": "http://www.google.com"
}
}API Documentation
new DeviceDetector([options])
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]> Passingnulldisables version truncation, so full versions will be returned. Defaults to1, only minor versions will be returned (e.g. X.Y).cache<[boolean | number]> TTL of the cache. Defaults totrue(no expiry).
Built with
- Matomo device detector - A powerful device detection library.
- node.js - Cross-platform JavaScript run-time environment for executing JavaScript code server-side.
- TypeScript - Typed superset of JavaScript that compiles to plain JavaScript.
- Jest - Delightful JavaScript Testing.
Contributing
When contributing to this project, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.
Update the README.md with details of changes to the library.
Execute npm run test and update the tests if needed.
Authors
- Etienne Martin - Initial work - etiennemartin.ca
License
This project is licensed under the MIT License - see the LICENSE file for details.