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

device-redirect

v1.0.2

Published

Redirect your users to device-specific apps and interstitial pages

Downloads

15

Readme

device-redirect

Redirect your users to device-specific apps and interstitial pages.

device-redirect is a JavaScript module that provides a simple API to redirect your users to device-specific app URLs, with fallbacks to interstitial or mobile friendly web pages.

Demo

We use device-redirect at Help Scout to let our iOS users know they can get the full mobile experience with our new iPhone App.

DeviceRedirectDemo

Installation

NPM

npm install device-redirect --save-dev

Bower

bower install https://npmcdn.com/device-redirect/bower.zip --save-dev

CDN (npmcdn.com)

https://npmcdn.com/device-redirect/dist/device-redirect.js
https://npmcdn.com/device-redirect/dist/device-redirect.min.js

Usage

Browser

<script src="device-redirect.min.js"></script>
<script>
    var dr = new DeviceRedirect(window.navigator.userAgent, { ...options });
</script>

AMD

define(['./path/to/device-redirect'], function(DeviceRedirect) {
  var dr = new DeviceRedirect(window.navigator.userAgent, { ...options });
});

CommonJS

// ES6
import DeviceRedirect from 'device-redirect'

// ES5
var DeviceRedirect = require('device-redirect');

var dr = new DeviceRedirect(window.navigator.userAgent, { ...options });

Methods

constructor(userAgent : string, <options : object>)

Creates a new DeviceRedirect instance for the specified user agent string. Example:

var dr = new DeviceRedirect(window.navigator.userAgent, {
	rules: { ... }
});

openApp()

Will try to redirect to the given appUrl for the matching device. If if fails to do that (this usually means the user doesn't have the native app installed in his device), it will redirect to the given redirectUrl for the matching device. Example:

var dr = new DeviceRedirect(window.navigator.userAgent, {
	rules: {
		'iOS': {
		    appUrl: 'my-iphone-app://article/1234',
		    redirectUrl: 'https://itunes.apple.com'
		}
	}
});

dr.openApp();

// On an iOS device, will try to open 'my-iphone-app://article/1234' on a native app.
// If it fails, it'll redirect to 'https://itunes.apple.com'.

Options

rules : object

A map object describing supported devices and URLs to redirect. Example:

var dr = new DeviceRedirect(window.navigator.userAgent, {
	rules: {
		'iOS': {
		    appUrl: 'my-iphone-app://article/1234',
		    redirectUrl: 'https://itunes.apple.com'
		},
		'AndroidOS': {
		    appUrl: 'my-android-app://article/1234',
		    redirectUrl: 'https://play.google.com'
		}
	}
});

Keys are used to match a user agent, OS, phone or tablet. This is the list of possible keys:

// General Keys:
Bot, MobileBot, DesktopMode, TV, WebKit, Console, Watch

// User Agent Keys:
Chrome, Dolfin, Opera, Skyfire, IE, Firefox, Bolt, TeaShark, Blazer, Safari, Tizen, UCBrowser, baiduboxapp, baidubrowser, DiigoBrowser, Puffin, Mercury, ObigoBrowser, NetFront, GenericBrowser

// OS Keys:
AndroidOS, BlackBerryOS, PalmOS, SymbianOS, WindowsMobileOS, WindowsPhoneOS, iOS, MeeGoOS, MaemoOS, JavaOS, webOS, badaOS, BREWOS

// Phone Keys:
iPhone, BlackBerry, HTC, Nexus, Dell, Motorola, Samsung, LG, Sony, Asus, Micromax, Palm, Vertu, Pantech, Fly, Wiko, iMobile, SimValley, Wolfgang, Alcatel, Nintendo, Amoi, INQ, GenericPhone

// Tablet Keys:
iPad, NexusTablet, SamsungTablet, Kindle, SurfaceTablet, HPTablet, AsusTablet, BlackBerryTablet, HTCtablet, MotorolaTablet, NookTablet, AcerTablet, ToshibaTablet, LGTablet, FujitsuTablet, PrestigioTablet, LenovoTablet, DellTablet, YarvikTablet, MedionTablet, ArnovaTablet, IntensoTablet, IRUTablet, MegafonTablet, EbodaTablet, AllViewTablet, ArchosTablet, AinolTablet, SonyTablet, PhilipsTablet, CubeTablet, CobyTablet, MIDTablet, MSITablet, SMiTTablet, RockChipTablet, FlyTablet, bqTablet, HuaweiTablet, NecTablet, PantechTablet, BronchoTablet, VersusTablet, ZyncTablet, PositivoTablet, NabiTablet, KoboTablet, DanewTablet, TexetTablet, PlaystationTablet, TrekstorTablet, PyleAudioTablet, AdvanTablet, DanyTechTablet, GalapadTablet, MicromaxTablet, KarbonnTablet, AllFineTablet, PROSCANTablet, YONESTablet, ChangJiaTablet, GUTablet, PointOfViewTablet, OvermaxTablet, HCLTablet, DPSTablet, VistureTablet, CrestaTablet, MediatekTablet, ConcordeTablet, GoCleverTablet, ModecomTablet, VoninoTablet, ECSTablet, StorexTablet, VodafoneTablet, EssentielBTablet, RossMoorTablet, iMobileTablet, TolinoTablet, AudioSonicTablet, AMPETablet, SkkTablet, TecnoTablet, JXDTablet, iJoyTablet, FX2Tablet, XoroTablet, ViewsonicTablet, OdysTablet, CaptivaTablet, IconbitTablet, TeclastTablet, OndaTablet, JaytechTablet, BlaupunktTablet, DigmaTablet, EvolioTablet, LavaTablet, AocTablet, CelkonTablet, WolderTablet, MiTablet, NibiruTablet, NexoTablet, LeaderTablet, UbislateTablet, PocketBookTablet, Hudl, TelstraTablet, GenericTablet

shouldRedirect : function

The default implementation of shouldRedirect always returns true. Overwrite this method to control if it should redirect to the URL specified in redirectUrl for the matching device. Example:

var dr = new DeviceRedirect(window.navigator.userAgent, {
	rules: { ... },
	shouldRedirect: function() {
		if(localStorage.getItem('userAlreadyOptedOutOfThisFeature')) {
			return false;
		}

		return true;
	}
});

Local Build

  • Clone this repo.
  • Install dependencies with npm install
  • Build project with npm run build
  • Run Unit Tests with npm test

Todo

  • Config ESLint
  • Config Travis-CI

License

MIT