Giter Site home page Giter Site logo

hom3chuk / ember-useragent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from willviles/ember-useragent

0.0 0.0 0.0 751 KB

An Ember addon for Fastboot-enabled UserAgent parsing via UAParser.js.

License: MIT License

JavaScript 89.50% HTML 7.90% Handlebars 2.60%

ember-useragent's Introduction

Ember UserAgent Build Status Ember Observer Score Download count all time npm

Ember UserAgent is an Ember Addon for UserAgent parsing via UAParser.js.

The userAgent service works in both browser & Fastboot environments and makes it easy to detect:

  • Device Type
  • Device Model
  • Browser
  • Operating System
  • Layout Engine
  • CPU architecture

Compatibility

  • Ember.js v3.8 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above

Installation

ember install ember-useragent

Usage

Ember UserAgent exposes a (1) service, which is automatically injected into controllers, components and routes, and a (2) template helper.

Service

const userAgent = this.get('userAgent');

userAgent.get('browser.isChrome'); // Boolean
userAgent.get('engine.isWebKit'); // Boolean
userAgent.get('os.info'); // => { name: 'Ubuntu', version: '11.10' }
userAgent.get('device.info'); // => { model: 'iPhone 7', type: 'mobile', vendor: 'Apple'}

Helper

{{#if (user-agent "browser.isChrome")}}
  Chrome, here...
{{/if}}

Service Properties

The service exposes all of UAParser's functions, but also adds some properties for quick access.

browser device engine os cpu
info info info info architecture
isChrome isConsole isWebKit isAndroid
isChromeHeadless isDesktop isIOS
isEdge isMobile isLinux
isFirefox isTablet isMacOS
isIE isWindows
isSafari

The service also exposes the userAgent property, which contains the user agent string. You can overwrite this property, if you want to force a certain user agent string. All of the properties described above will update in accordance.

Manual Usage

Ember UserAgent auto imports ua-parser-js into your application using ember-auto-import:

import UAParser from 'ua-parser-js';

Injection

By default, this addon will generate an initializer in app/initializers/user-agent.js that injects the userAgent service app-wide. If the userAgent property conflicts with other addons or you wish to use manual injection (Ember.service.inject) you can override this file.

Using UAParser.js

For more information on how to use UAParser.js, please refer to the documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.