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-sherlock

v0.2.1

Published

Powerful, lightweight device detector module.

Downloads

4

Readme

Device Sherlock

Powerful, lightweight device detector module.

Available for Javascript, Typescript, Vue, React and Angular

Note: This module is not a device detector, it's a device type detector. This module is ECMAScript modules (ESM) only.

Installation

NPM:

npm i device-sherlock

PNPM:

pnpm add device-sherlock

Yarn:

yarn add device-sherlock

Use

import { deviceSherlock } from 'device-sherlock';

or:

import pkg from 'device-sherlock';
const { deviceSherlock } = pkg;

That's it, you can now use deviceSherlock in your app ✨

Flags

You can use these flags to detect the device type.

deviceSherlock.isDesktop
deviceSherlock.isMobile
deviceSherlock.isTablet
deviceSherlock.isMobileOrTablet
deviceSherlock.isDesktopOrTablet
deviceSherlock.isIos
deviceSherlock.isWindows
deviceSherlock.isMacOS
deviceSherlock.isApple
deviceSherlock.isAndroid
deviceSherlock.isFirefox
deviceSherlock.isEdge
deviceSherlock.isChrome
deviceSherlock.isSafari
deviceSherlock.isSamsung
deviceSherlock.isCrawler
deviceSherlock.isUnknown
deviceSherlock.isCloudFront
deviceSherlock.isCloudflare
deviceSherlock.userAgent

The user agent is also injected an accessible with deviceSherlock.userAgent.

Settings

You can set the user agent manually.

deviceSherlock.setUserAgent('Mozilla/5.0 (Linux; Android 10; SM-G960U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.181 Mobile Safari/537.36');

You can define headers manually.

deviceSherlock.setHeaders({
  'CF-Device-Type': 'mobile',
  'CloudFront-Is-Mobile-Viewer': 'true',
  'CloudFront-Is-Tablet-Viewer': 'false',
  'CloudFront-Is-Desktop-Viewer': 'false',
  'CloudFront-Is-Ios-Viewer': 'false',
  'CloudFront-Is-Android-Viewer': 'true',
});

Usage

Vue, React, Angular

You can use deviceSherlock inside a script to access the flags.

<script setup>
import { deviceSherlock } from 'device-sherlock'
import pkg from 'device-sherlock';
const { deviceSherlock } = pkg;
</script>

Switch a view

<template>
  <section>
    <div v-if="deviceSherlock.isDesktop">
      Desktop
    </div>
    <div v-else-if="deviceSherlock.isTablet">
      Tablet
    </div>
    <div v-else>
      Mobile
    </div>
  </section>
</template>

CloudFront Support

If the user-agent is Amazon CloudFront, this module checks the following headers:

  • CloudFront-Is-Mobile-Viewer
  • CloudFront-Is-Tablet-Viewer
  • CloudFront-Is-Desktop-Viewer
  • CloudFront-Is-Ios-Viewer
  • CloudFront-Is-Android-Viewer

Here are the details about the headers: Amazon CloudFront - Headers for determining the viewer's device type.

Caution

isWindows, isLinux and isMacOS flags are not available with CloudFront.

Cloudflare Support

This module checks the header CF-Device-Type.

Here are the details about the header.

License

CORE

Data Source

This module uses crawler-user-agents to generate the regular expression that detect a crawler.

Note

This module inspired by @healerlab/device-js module.