Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-useragent

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-useragent

next-useragent parses browser user-agent strings for next.js.

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
increased by49.72%
Maintainers
1
Weekly downloads
 
Created
Source

next-useragent

next-useragent parses browser user-agent strings for next.js.

npm

Installation

$ npm install next-useragent

Usage

next-useragent is simple to use.
Give access to user-agent details anywhere using withUserAgent method.

  • As ua property of context of getInitialProps.
  • As component ua property of this.props

Example usage:

import React from 'react'
import { UserAgentProps, withUserAgent } from 'next-useragent'

class IndexPage extends React.Component<UserAgentProps> {

  static async getInitialProps(ctx) {
    // ctx.ua
    // => `UserAgent` type object.

    return {}
  }

  render() {
    const { ua } = this.props

    return (
      <ul>
        <li>Original source: { ua.source }</li>
        <li>Device Type: { ua.deviceType }</li>
        <li>Device Vendor: { ua.deviceVendor }</li>
        <li>OS Name: { ua.os }</li>
        <li>OS Version: { ua.osVersion }</li>
        <li>Browser Name: { ua.browser }</li>
        <li>Browser Version: { ua.browserVersion }</li>
        <li>is iPhone?: { ua.isIphone ? 'yes' : 'no' }</li>
        <li>is iPad?: { ua.isIpad ? 'yes' : 'no' }</li>
        <li>is mobile?: { ua.isMobile ? 'yes' : 'no' }</li>
        <li>is tablet?: { ua.isTablet ? 'yes' : 'no' }</li>
        <li>is desktop?: { ua.isDesktop ? 'yes' : 'no' }</li>
        <li>is Chrome?: { ua.isChrome ? 'yes' : 'no' }</li>
        <li>is Firefox?: { ua.isFirefox ? 'yes' : 'no' }</li>
        <li>is Safari?: { ua.isSafari ? 'yes' : 'no' }</li>
        <li>is Internet Explorer?: { ua.isIE ? 'yes' : 'no' }</li>
        <li>is Mac?: { ua.isMac ? 'yes' : 'no' }</li>
        <li>is ChromeOS?: { ua.isChromeOS ? 'yes' : 'no' }</li>
        <li>is Windows?: { ua.isWindows ? 'yes' : 'no' }</li>
        <li>is iOS?: { ua.isIos ? 'yes' : 'no' }</li>
        <li>is Android?: { ua.isAndroid ? 'yes' : 'no' }</li>
        <li>is bot?: { ua.isBot ? 'yes' : 'no' }</li>
      </ul>
    )
  }
}

export default withUserAgent(IndexPage)

License

next-useragent is licensed under MIT License.
See LICENSE for more information.

Keywords

FAQs

Package last updated on 30 Apr 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc