Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/willviles/ember-useragent
An Ember addon for Fastboot-enabled UserAgent parsing via UAParser.js.
https://github.com/willviles/ember-useragent
browser-detection device-detector device-recognition ember ember-addon ember-fastboot mobile-detection ua-parser useragent
Last synced: about 2 months ago
JSON representation
An Ember addon for Fastboot-enabled UserAgent parsing via UAParser.js.
- Host: GitHub
- URL: https://github.com/willviles/ember-useragent
- Owner: willviles
- License: mit
- Created: 2017-02-10T14:27:30.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-27T10:52:07.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T22:09:49.964Z (2 months ago)
- Topics: browser-detection, device-detector, device-recognition, ember, ember-addon, ember-fastboot, mobile-detection, ua-parser, useragent
- Language: JavaScript
- Homepage:
- Size: 3.86 MB
- Stars: 37
- Watchers: 3
- Forks: 12
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
Ember UserAgent [![Build Status](https://travis-ci.org/willviles/ember-useragent.svg)](https://travis-ci.org/willviles/ember-useragent) [![Ember Observer Score](http://emberobserver.com/badges/ember-useragent.svg)](http://emberobserver.com/addons/ember-useragent) ![Download count all time](https://img.shields.io/npm/dt/ember-useragent.svg) [![npm](https://img.shields.io/npm/v/ember-useragent.svg)](https://www.npmjs.com/package/ember-useragent)
======Ember UserAgent is an Ember Addon for UserAgent parsing via [UAParser.js](https://github.com/faisalman/ua-parser-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 aboveInstallation
------------------------------------------------------------------------------```
ember install ember-useragent
```## Usage
Ember UserAgent exposes a service and a template helper.
### Service
```javascript
import { inject as service } from '@ember/service';export default class FooComponent extends Component {
@service userAgent;
}
``````javascript
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
```handlebars
{{#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](https://github.com/ef4/ember-auto-import):
```js
import UAParser from 'ua-parser-js';
```### Injection
Prior to `0.11.0`, this addon generated an initializer in `app/initializers/user-agent.js` that injected the `userAgent` service across all controllers, components and routes. This does not happen in `>=0.11.0`.
You can restore this behavior by manually performing these implicit injections (see [#42](https://github.com/willviles/ember-useragent/pull/42)), however this is highly discouraged, as this feature is deprecated by the upcoming Ember `v4.0`. If you were relying on these implicit injections, you should instead refactor your code to explicitly inject the `userAgent` service.
## Using UAParser.js
For more information on how to use UAParser.js, please refer to the [documentation](https://github.com/faisalman/ua-parser-js#methods).