npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-is-mobile

v4.1.2

Published

Detect requests from mobile devices in your Ember apps.

Downloads

1,592

Readme

ember-is-mobile

Build Status

Detect requests from mobile devices in your Ember apps.

This addon uses isMobile.js for parsing user agent strings. Works seamlessly in both the browser and in FastBoot.

Install

ember install ember-is-mobile

Compatibility

  • Ember.js v3.16 or above
  • Ember CLI v2.13 or above
  • Node.js v10 or above

Usage

As a service

The isMobile service provides access to the results of the user agent tests provided by isMobile.js. This service works in both the browser and in FastBoot. The FastBoot support is particularly useful if you want to conditionally render large blocks of content to target desktop or mobile devices.

You can query the user agent tests in your controllers, components and routes:

import Component from '@ember/component';

export default class extends Component {
  @service isMobile;

  constructor() {
    super(...arguments);
    console.log(this.isMobile.any); // => true|false
  }
}
{{#if this.isMobile.any}}
  I'm on a mobile device!
{{/if}}

As a helper

The is-mobile helper can be used as an alternative to isMobile service. It takes an optional argument — a string specifying the user agent test.

{{#if (is-mobile "any")}}
  I'm on a mobile device
{{/if}}
<div class="{{if (is-mobile "android.phone") "is-android"}} {{if (is-mobile "apple.phone") "is-apple"}}">
  I'm on a mobile device
</div>

Directly

This addon also re-exports isMobile.js, so you can import it yourself if you need to. In most cases you should use the service instead.

import isMobile from 'ember-is-mobile';

In the browser, you can call the isMobile function with no arguments.

isMobile(); // => { apple: {}, windows: {}, ... }

In FastBoot, however, you need to fetch the FastBoot headers yourself and run the method manually. Note that this syntax will only work in FastBoot.

if (this.get('fastboot.isFastBoot')) {
    let headers = this.get('fastboot.request.headers');
    let userAgent = headers.get('user-agent');
    isMobile(userAgent); // => { apple: {}, windows: {}, ... }
}

Contributing

See the Contributing guide for details.

For more information on using ember-cli, visit https://ember-cli.com/.

License

MIT © Sander Melnikov.