0.1.6 • Published 5 years ago

@apilayer/userstack v0.1.6

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

userstack-js

Userstack provides an API to Detect any Browser, Device & OS in Real-Time

Installation

Using npm

npm install --save @apilayer/userstack

or yarn

yarn add @apilayer/userstack

Getting Started

Head over to Userstack and create an account. Copy access key from dashboard.

import userstack from '@apilayer/userstack'

const useHTTPs = false
const layer = new userstack("<your-access-key>", useHTTPs)

detect

detect Look up any given User-Agent string.

Signature:

detect(ua: string): Promise<Response>

Example:

const response = layer.detect("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36")

console.log('response:', response)

Response:

{
  ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
  type: "browser",
  brand: "Apple",
  name: "Mac",
  url: "https://www.google.com/about/company/",
  os: {
    name: "macOS 10.14 Mojave",
    code: "macos_10_14",
    url: "https://en.wikipedia.org/wiki/MacOS_Mojave",
    family: "macOS",
    family_code: "macos",
    family_vendor: "Apple Inc.",
    icon: "https://assets.userstack.com/icons/os/macosx.png",
    icon_large: "https://assets.userstack.com/icons/os/macosx_big.png"
  },
  device: {
    is_mobile_device: false,
    type: "desktop",
    brand: "Apple",
    brand_code: "apple",
    brand_url: "http://www.apple.com/",
    name: "Mac"
  },
  browser: {
    name: "Chrome",
    version: "71.0.3578.98",
    version_major: "71",
    engine: "WebKit/Blink"
  },
  crawler: {
    is_crawler: false,
    category: null,
    last_seen: null
  }
}

BulkDetect

BulkDetect Look up multiple User-Agent strings in bulk.

Signature:

bulkDetect(ua_batch: string[]): Promise<Response[]>

Example:

const response = layer.bulkDetect([
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
])

console.log('response:', response)

Response:

[{
  ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
  type: "browser",
  brand: "Apple",
  name: "Mac",
  url: "https://www.google.com/about/company/",
  os: {
    name: "macOS 10.14 Mojave",
    code: "macos_10_14",
    url: "https://en.wikipedia.org/wiki/MacOS_Mojave",
    family: "macOS",
    family_code: "macos",
    family_vendor: "Apple Inc.",
    icon: "https://assets.userstack.com/icons/os/macosx.png",
    icon_large: "https://assets.userstack.com/icons/os/macosx_big.png"
  },
  device: {
    is_mobile_device: false,
    type: "desktop",
    brand: "Apple",
    brand_code: "apple",
    brand_url: "http://www.apple.com/",
    name: "Mac"
  },
  browser: {
    name: "Chrome",
    version: "71.0.3578.98",
    version_major: "71",
    engine: "WebKit/Blink"
  },
  crawler: {
    is_crawler: false,
    category: null,
    last_seen: null
  }
}]

License

MIT