2.1.0 • Published 2 months ago

who-am-i-now v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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)
selectortypeexplanation
isReactNativeAppbooleanreturns true if code is running in a react-native app (with and without expo)
isReactNativeAppIOSbooleanreturns true if code is running in a react-native app (with and without expo) and if the platform is ios
isReactNativeAppAndroidbooleanreturns true if code is running in a react-native app (with and without expo) and if the platform is android
isReactNativeAppWebbooleanreturns 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!)
isExpoAppbooleanreturns true if code is running in a react-native app via expo
isExpoAppRunningInGoboolean | undefinedreturns 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
isExpoSnackboolean | undefinedreturns 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
isReactAppbooleanreturns true if code is running in a react app
isNextAppbooleanreturns true if code is running in a nextjs app
isTWAbooleanreturns true if code is running as part of an android trusted web activities app
isPWAStandalonebooleanreturns 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.)
isServerAppbooleanreturns true if code is running in a plain node "server" app (imagine a classical express api/server for instance)
isCIbooleanreturns 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)
isTestRunbooleanreturns 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)
isJestTestRunbooleanreturns true if code is running as part of a jest test run
isCypressTestRunbooleanreturns true if code is running as part of a cypress test run
isBrowser*booleanreturns true if code is running in a browser - the behaviour from react-device-detect was slightly changed
isMobile*booleanreturns true if code is running in a react-native app (with and without expo) but not in web browser (via react-native-web)
isDesktop*booleanreturns 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**booleanreturns the same value react-device-detect returns
isTablet**booleanreturns the same value react-device-detect returns
isSmartTV**booleanreturns the same value react-device-detect returns
isWearable**booleanreturns the same value react-device-detect returns
isConsole**booleanreturns the same value react-device-detect returns
isEmbedded**booleanreturns the same value react-device-detect returns
isAndroid**booleanreturns the same value react-device-detect returns
isWinPhone**booleanreturns the same value react-device-detect returns
isIOS**booleanreturns the same value react-device-detect returns
isChrome**booleanreturns the same value react-device-detect returns
isFirefox**booleanreturns the same value react-device-detect returns
isSafari**booleanreturns the same value react-device-detect returns
isOpera**booleanreturns the same value react-device-detect returns
isIE**booleanreturns the same value react-device-detect returns
isEdge**booleanreturns the same value react-device-detect returns
isYandex**booleanreturns the same value react-device-detect returns
isChromium**booleanreturns the same value react-device-detect returns
isMobileSafari**booleanreturns the same value react-device-detect returns
isSamsungBrowser**booleanreturns the same value react-device-detect returns
osVersion**stringreturns the same value react-device-detect returns
osName**stringreturns the same value react-device-detect returns
fullBrowserVersion**stringreturns the same value react-device-detect returns
browserVersion**stringreturns the same value react-device-detect returns
browserName**stringreturns the same value react-device-detect returns
mobileVendor**stringreturns the same value react-device-detect returns
mobileModel**stringreturns the same value react-device-detect returns
engineName**stringreturns the same value react-device-detect returns
engineVersion**stringreturns the same value react-device-detect returns
getUA**stringreturns the same value react-device-detect returns
deviceType**stringreturns the same value react-device-detect returns
isIOS13**booleanreturns the same value react-device-detect returns
isIPhone13**booleanreturns the same value react-device-detect returns
isIPad13**booleanreturns the same value react-device-detect returns
isIPod13**booleanreturns the same value react-device-detect returns
isElectron**booleanreturns the same value react-device-detect returns
isEdgeChromium**booleanreturns the same value react-device-detect returns
isLegacyEdge**booleanreturns the same value react-device-detect returns
isWindows**booleanreturns the same value react-device-detect returns
isMacOs**booleanreturns the same value react-device-detect returns

Misc

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

If you enjoy using this...

2.0.3

2 months ago

2.0.2

2 months ago

2.0.4

2 months ago

2.1.0

2 months ago

2.0.1

2 months ago

2.0.0

2 months ago

1.0.8

2 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

12 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago