nuxt-ua

UserAgent detector using platform for Nuxt
3,934 6
Install
npm install nuxt-ua
Latest Version:2.0.0
Vue:3
Older releases:2
License:MIT
Last Updated:Sep 13, 2023
Links: GitHub  ·  npm
Maintainer: 1000ch

nuxt-ua GitHub Actions Status

UserAgent detector using Platform.js for Nuxt.

Install

npm install --save nuxt-ua

Usage

This module is compatible with Nuxt 2, Nuxt 3 and Nuxt-bridge.

Add 'nuxt-ua' to your modules array in the nuxt.config.ts file:

modules: [
  // other modules...
  'nuxt-ua',
]

Nuxt 2 types

If you are using TypeScript in a Nuxt2 project, please add nuxt-ua/types to your tsconfig.json file to inject $ua into the Context:

{
  "compilerOptions": {
    // ..
    "types": [
      "@nuxt/types",
      "@types/node",
      "nuxt-ua/types"
    ]
  }
}

Then, you can use the `$ua` object:

```html
<template>
  <main>
    {{ $ua.is.chrome ? 'This is Chrome' : 'This is not Chrome' }}
  </main>
</template>

<script lang="ts">
import Vue from 'vue';
import { Context } from '@nuxt/vue-app/types';

export default Vue.extend({
  fetch(context: Context) {
    console.log(context.$ua);
  }
});
</script>

API

$ua.platform

Returns a Platform object.

$ua.is.chrome

Returns true if the UserAgent is Chrome.

$ua.is.firefox

Returns true if the UserAgent is Firefox.

$ua.is.safari

Returns true if the UserAgent is Safari.

$ua.is.ie

Returns true if the UserAgent is Internet Explorer.

$ua.is.edge

Returns true if the UserAgent is Microsoft Edge.

$ua.is.opera

Returns true if the UserAgent is Opera.

$ua.is.android

Returns true if the UserAgent is Android.

$ua.is.ios

Returns true if the UserAgent is iOS.

$ua.is.macos

Returns true if the UserAgent is macOS.

$ua.is.windows

Returns true if the UserAgent is Windows.

$ua.is.linux

Returns true if the UserAgent is Linux.

Development

  1. Install the development dependencies
npm ci
  1. Initialize the Nuxt playground
npm run dev:prepare
  1. Run the development environment
npm run dev
  1. Add or modify the tests and ensure that tests are passing
npm test

License

MIT © Shogo Sensui

Related Packages

nuxt-user-agent

Nuxt.js module for handling User-Agent.

272,403 121
@scayle/storefront-nuxt

Nuxt integration for the SCAYLE Commerce Engine and Storefront API

152,903
nuxt-tsconfig-stub

Stub Nuxt's generated tsconfig.json at installation

70,835 24
kuranuxt

Look at the Nuxt 3 documentation to learn more.

990 0
nuxt-define

One utility function for module authors to define compiler constants for all bui...

13,412,511

Version History

Version Released Vue License
2.0.0 ^3.0 MIT
1.0.8 ^2.0.0 MIT
1.0.7 ^2.0.0 MIT
1.0.6 ^2.0.0 MIT
1.0.5 ^2.0.0 MIT