capacitor-firebase-kit
Version:
Provider-less Firebase Kit - Universal Firebase services integration for React, React Native, and Capacitor apps
53 lines • 1.66 kB
JavaScript
class PlatformDetector {
constructor() {
this.cachedPlatform = null;
}
detect() {
if (this.cachedPlatform) {
return this.cachedPlatform;
}
const info = {
platform: 'web',
isWeb: false,
isReactNative: false,
isCapacitor: false,
isNode: false,
hasDOM: false,
};
// Check if we're in Node.js environment
if (typeof process !== 'undefined' && process.versions && process.versions.node) {
info.platform = 'node';
info.isNode = true;
this.cachedPlatform = info;
return info;
}
// Check for DOM availability
info.hasDOM = typeof window !== 'undefined' && typeof document !== 'undefined';
// Check for React Native
if (typeof global !== 'undefined' && global.nativePerformanceNow) {
info.platform = 'react-native';
info.isReactNative = true;
this.cachedPlatform = info;
return info;
}
// Check for Capacitor
if (info.hasDOM && window.Capacitor) {
info.platform = 'capacitor';
info.isCapacitor = true;
this.cachedPlatform = info;
return info;
}
// Default to web
if (info.hasDOM) {
info.platform = 'web';
info.isWeb = true;
}
this.cachedPlatform = info;
return info;
}
reset() {
this.cachedPlatform = null;
}
}
export const platformDetector = new PlatformDetector();
//# sourceMappingURL=platform-detector.js.map