🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

nuxt-user-agent

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuxt-user-agent

Nuxt.js module for handling User-Agent.

1.2.2
latest
Source
npm
Version published
Weekly downloads
7.5K
-38.72%
Maintainers
1
Weekly downloads
 
Created
Source

nuxt-user-agent

MIT License npm version

Nuxt.js module for handling User-Agent.

Inspired by rack-user-agent and, Thanks to woothee :pray:

Setup

Install with yarn:

yarn add nuxt-user-agent

Install with npm:

npm install nuxt-user-agent

nuxt.config.js

module.exports = {
  modules: [
    'nuxt-user-agent',
  ]
}

Usage

Component

asyncData
asyncData(context) {
  const deviceType = context.$ua.deviceType()
  return { deviceType }
}
methods/created/mounted/etc
methods: {
  something() {
    const deviceType = this.$ua.deviceType()
    this.deviceType = deviceType
  }
}
Store actions
// In store
{
  actions: {
    getDeviceType ({ commit }) {
      const deviceType = this.$ua.deviceType()
      commit('SET_DEVICE_TYPE', deviceType)
    }
  }
}
template
<template>
  <section>
    <div v-if="$ua.isFromPc()">
      <span>PC</span>
    </div>
    <div v-if="$ua.isFromSmartphone()">
      <span>Smartphone</span>
    </div>
    <div v-if="$ua.isFromMobilephone()">
      <span>Mobilephone</span>
    </div>
    <div v-if="$ua.isFromTablet()">
      <span>Tablet</span>
    </div>
    <div v-if="$ua.isFromAppliance()">
      <span>Appliance</span>
    </div>
    <div v-if="$ua.isFromCrawler()">
      <span>Crawler</span>
    </div>
  </section>
</template>

Methods

methodtypeexample
deviceTypestringpc
osstringMac OSX
osVersionstring10.12.6
browserstringChrome
browserVersionstring65.0.3325.181
browserVendorstringGoogle
isFromIphonebooleantrue
isFromIpadbooleantrue
isFromIpodbooleantrue
isFromIosbooleantrue
isFromAndroidMobilebooleantrue
isFromAndroidTabletbooleantrue
isFromAndroidOsbooleantrue
isFromWindowsPhonebooleantrue
isFromPcbooleantrue
isFromSmartphonebooleantrue
isFromMobilephonebooleantrue
isFromAppliancebooleantrue
isFromCrawlerbooleantrue
isFromTabletbooleantrue

TODO

  • unit test

License

The npm is available as open source under the terms of the MIT License.

Keywords

Nuxt.js

FAQs

Package last updated on 10 Sep 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