@react-native-module/utility
Version:
@react-native-module/utility
31 lines (29 loc) • 1.1 kB
JavaScript
const PlatformType = (function () {
const isReactNative = globalThis?.navigator?.product === 'ReactNative';
if (isReactNative) {
try {
// check if exists (or throw error)
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unused-vars
const reactNative = require('react-native');
const usingHermes = typeof HermesInternal === 'object' && HermesInternal !== null;
if (usingHermes)
return 'Hermes';
return 'JavaScriptCore';
}
catch (error) {
// do nothing
}
}
if (typeof globalThis.document !== 'undefined') {
return 'Browser';
}
return 'NodeJs';
})();
const isRunningOnNativeMobile = PlatformType === 'JavaScriptCore' || PlatformType === 'Hermes';
const isRunningOnBrowser = PlatformType === 'Browser';
const Environment = isRunningOnNativeMobile
? 'NativeMobile'
: isRunningOnBrowser
? 'Browser'
: 'NodeJs';
export { Environment, PlatformType };