2.0.0 • Published 1 year ago

nuxt-ua v2.0.0

Weekly downloads
91
License
MIT
Repository
github
Last release
1 year ago

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

2.0.0

1 year ago

1.0.8

2 years ago

1.0.7

3 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.13.0

5 years ago

0.12.1

5 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.10.0

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.0

5 years ago