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

who-am-i-now

v2.1.1

Published

Platform detection: NodeJS? React? ReactNative? Expo? etc.

Downloads

464

Readme

who-am-i-now

Version

Which platform am I on?

Do you need to run platform specific code?

If you need to (programmatically) find the answer to one of the following questions then this package is for you:

  • "is my app a react frontend?"
  • "is my app a nextjs app?"
  • "is my app a PWA standalone (installed) app?"
  • "is my app a react-native app?"
  • "is my app an expo app?"
  • "is my react-native or expo app running on ios, android or web?"
  • "is my app a plain node server?"
  • etc.

This package is extending the functionality of react-device-detect, by additionally detecting which 'platform' your code is running on and other things.

Live demos

Using who-am-i-now in an expo app

https://snack.expo.dev/@maks-io/who-am-i-now-demo

Using who-am-i-now in a react app

https://stackblitz.com/edit/who-am-i-now-react

Using who-am-i-now in a next.js app

https://stackblitz.com/edit/who-am-i-now-nextjs

Installation

Via npm:

npm i who-am-i-now --save

Via yarn:

yarn add who-am-i-now

Usage

import WhoAmINow, { Who } from "who-am-i-now";

const who: Who = WhoAmINow();

// Example result:
// who = {
//     isMobile: true,
//     isBrowser: false,
//     isReactNativeApp: true,
//     isReactNativeAppIOS: true,
//     isReactNativeAppAndroid: false,
//     isReactNativeAppWeb: false,
//     isExpoApp: true,
//     isReactApp: false,
//     isNextApp: false,
//     isTWA: false,
//     isPWAStandalone: false,
//     isServerApp: false,
//     ... and many others - check section below for details
// }

Selectors

The result of calling whoAmINow() is an object holding various selectors/booleans/values. Every prop is either

  • inheriting the behaviour from the original react-device-detect library (entries marked with **), or
  • having a different behaviour compared to the original react-device-detect library (entries marked with *), or
  • completely new (entries in table without asterisks)

| selector | type | explanation | | ----------------------- | -------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | isReactNativeApp | boolean | returns true if code is running in a react-native app (with and without expo) | | isReactNativeAppIOS | boolean | returns true if code is running in a react-native app (with and without expo) and if the platform is ios | | isReactNativeAppAndroid | boolean | returns true if code is running in a react-native app (with and without expo) and if the platform is android | | isReactNativeAppWeb | boolean | returns true if code is running in a react-native app (with and without expo) and if the platform is web (Note that this will be false if code is running in a plain react web app!) | | isExpoApp | boolean | returns true if code is running in a react-native app via expo | | isExpoAppRunningInGo | boolean | undefined | returns true if code is running in expo Go, returns false otherwise, if it is still an expo app, and returns undefined in every other case | | isExpoSnack | boolean | undefined | returns true if code is running in an expo snack, returns false otherwise, if it is still an expo app, and returns undefined in every other case | | isReactApp | boolean | returns true if code is running in a react app | | isNextApp | boolean | returns true if code is running in a nextjs app | | isTWA | boolean | returns true if code is running as part of an android trusted web activities app | | isPWAStandalone | boolean | returns true if code is running as part of a progressive web app / PWA in standalone mode, meaning in an installed way (for instance, after user decided to "add app to homescreen" etc.) | | isServerApp | boolean | returns true if code is running in a plain node "server" app (imagine a classical express api/server for instance) | | isCI | boolean | returns true if code is running as part of a continuous integration / CI pipeline (since version 2.1.0 it relies on the is-ci package) | | isTestRun | boolean | returns true if code is running as part of a test run (for instance jest unit tests, etc. - it relies on the environment to set the variable NODE_ENV=test) | | isJestTestRun | boolean | returns true if code is running as part of a jest test run | | isCypressTestRun | boolean | returns true if code is running as part of a cypress test run | | isBrowser* | boolean | returns true if code is running in a browser - the behaviour from react-device-detect was slightly changed | | isMobile* | boolean | returns true if code is running in a react-native app (with and without expo) but not in web browser (via react-native-web) | | isDesktop* | boolean | returns true if code is NOT running in a react-native app (with and without expo) - in other words, this is the opposite of isMobile above | | isMobileOnly** | boolean | returns the same value react-device-detect returns | | isTablet** | boolean | returns the same value react-device-detect returns | | isSmartTV** | boolean | returns the same value react-device-detect returns | | isWearable** | boolean | returns the same value react-device-detect returns | | isConsole** | boolean | returns the same value react-device-detect returns | | isEmbedded** | boolean | returns the same value react-device-detect returns | | isAndroid** | boolean | returns the same value react-device-detect returns | | isWinPhone** | boolean | returns the same value react-device-detect returns | | isIOS** | boolean | returns the same value react-device-detect returns | | isChrome** | boolean | returns the same value react-device-detect returns | | isFirefox** | boolean | returns the same value react-device-detect returns | | isSafari** | boolean | returns the same value react-device-detect returns | | isOpera** | boolean | returns the same value react-device-detect returns | | isIE** | boolean | returns the same value react-device-detect returns | | isEdge** | boolean | returns the same value react-device-detect returns | | isYandex** | boolean | returns the same value react-device-detect returns | | isChromium** | boolean | returns the same value react-device-detect returns | | isMobileSafari** | boolean | returns the same value react-device-detect returns | | isSamsungBrowser** | boolean | returns the same value react-device-detect returns | | osVersion** | string | returns the same value react-device-detect returns | | osName** | string | returns the same value react-device-detect returns | | fullBrowserVersion** | string | returns the same value react-device-detect returns | | browserVersion** | string | returns the same value react-device-detect returns | | browserName** | string | returns the same value react-device-detect returns | | mobileVendor** | string | returns the same value react-device-detect returns | | mobileModel** | string | returns the same value react-device-detect returns | | engineName** | string | returns the same value react-device-detect returns | | engineVersion** | string | returns the same value react-device-detect returns | | getUA** | string | returns the same value react-device-detect returns | | deviceType** | string | returns the same value react-device-detect returns | | isIOS13** | boolean | returns the same value react-device-detect returns | | isIPhone13** | boolean | returns the same value react-device-detect returns | | isIPad13** | boolean | returns the same value react-device-detect returns | | isIPod13** | boolean | returns the same value react-device-detect returns | | isElectron** | boolean | returns the same value react-device-detect returns | | isEdgeChromium** | boolean | returns the same value react-device-detect returns | | isLegacyEdge** | boolean | returns the same value react-device-detect returns | | isWindows** | boolean | returns the same value react-device-detect returns | | isMacOs** | boolean | returns the same value react-device-detect returns |

Misc

Youtube short: https://youtube.com/shorts/sKyRYo9h514?feature=share

If you enjoy using this...