JSPM

  • Created
  • Published
  • Downloads 126451
  • Score
    100M100P100Q163207F
  • License LGPL-3.0

A Node.js port of Matomo device-detector

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.

Coveralls github CircleCI build node version npm version npm monthly downloads

Getting Started

Installation

To use device-detector-js in your project, run:

npm install device-detector-js

Usage

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 to false.
    • versionTruncation <[0 | 1 | 2 | 3 | null]> Passing null disables version truncation, so full versions will be returned. Defaults to 1, only minor versions will be returned (e.g. X.Y).
    • cache <[boolean | number]> TTL of the cache (in seconds). Defaults to true (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

License

This project is licensed under the MIT License - see the LICENSE file for details.