peerpigeon 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,430 +3,430 @@
3
3
  * Provides comprehensive environment detection for browser, Node.js, Worker contexts
4
4
  */
5
5
  export class EnvironmentDetector {
6
- constructor() {
7
- this._cache = new Map();
8
- this._init();
9
- }
10
-
11
- _init() {
12
- // Pre-compute common detections to avoid repeated checks
13
- this._cache.set('isBrowser', this._detectBrowser());
14
- this._cache.set('isNodeJS', this._detectNodeJS());
15
- this._cache.set('isWorker', this._detectWorker());
16
- this._cache.set('isServiceWorker', this._detectServiceWorker());
17
- this._cache.set('isWebWorker', this._detectWebWorker());
18
- this._cache.set('isSharedWorker', this._detectSharedWorker());
19
- this._cache.set('isDeno', this._detectDeno());
20
- this._cache.set('isBun', this._detectBun());
21
- }
22
-
23
- // Primary environment detection
24
- _detectBrowser() {
25
- return typeof window !== 'undefined' &&
26
- typeof document !== 'undefined' &&
6
+ constructor() {
7
+ this._cache = new Map();
8
+ this._init();
9
+ }
10
+
11
+ _init() {
12
+ // Pre-compute common detections to avoid repeated checks
13
+ this._cache.set('isBrowser', this._detectBrowser());
14
+ this._cache.set('isNodeJS', this._detectNodeJS());
15
+ this._cache.set('isWorker', this._detectWorker());
16
+ this._cache.set('isServiceWorker', this._detectServiceWorker());
17
+ this._cache.set('isWebWorker', this._detectWebWorker());
18
+ this._cache.set('isSharedWorker', this._detectSharedWorker());
19
+ this._cache.set('isDeno', this._detectDeno());
20
+ this._cache.set('isBun', this._detectBun());
21
+ }
22
+
23
+ // Primary environment detection
24
+ _detectBrowser() {
25
+ return typeof window !== 'undefined' &&
26
+ typeof document !== 'undefined' &&
27
27
  typeof navigator !== 'undefined';
28
- }
28
+ }
29
29
 
30
- _detectNodeJS() {
31
- return typeof process !== 'undefined' &&
32
- process.versions != null &&
30
+ _detectNodeJS() {
31
+ return typeof process !== 'undefined' &&
32
+ process.versions != null &&
33
33
  process.versions.node != null;
34
- }
34
+ }
35
35
 
36
- _detectDeno() {
37
- return typeof Deno !== 'undefined';
38
- }
36
+ _detectDeno() {
37
+ return typeof Deno !== 'undefined';
38
+ }
39
39
 
40
- _detectBun() {
41
- return typeof Bun !== 'undefined';
42
- }
40
+ _detectBun() {
41
+ return typeof Bun !== 'undefined';
42
+ }
43
43
 
44
- _detectWorker() {
45
- return typeof importScripts !== 'undefined' ||
46
- this._detectServiceWorker() ||
47
- this._detectWebWorker() ||
44
+ _detectWorker() {
45
+ return typeof importScripts !== 'undefined' ||
46
+ this._detectServiceWorker() ||
47
+ this._detectWebWorker() ||
48
48
  this._detectSharedWorker();
49
- }
50
-
51
- _detectServiceWorker() {
52
- return typeof ServiceWorkerGlobalScope !== 'undefined' &&
53
- typeof self !== 'undefined' &&
54
- self instanceof ServiceWorkerGlobalScope;
55
- }
56
-
57
- _detectWebWorker() {
58
- return typeof DedicatedWorkerGlobalScope !== 'undefined' &&
59
- typeof self !== 'undefined' &&
60
- self instanceof DedicatedWorkerGlobalScope;
61
- }
62
-
63
- _detectSharedWorker() {
64
- return typeof SharedWorkerGlobalScope !== 'undefined' &&
65
- typeof self !== 'undefined' &&
66
- self instanceof SharedWorkerGlobalScope;
67
- }
68
-
69
- // Public getters
70
- get isBrowser() {
71
- return this._cache.get('isBrowser');
72
- }
73
-
74
- get isNodeJS() {
75
- return this._cache.get('isNodeJS');
76
- }
77
-
78
- get isWorker() {
79
- return this._cache.get('isWorker');
80
- }
81
-
82
- get isServiceWorker() {
83
- return this._cache.get('isServiceWorker');
84
- }
85
-
86
- get isWebWorker() {
87
- return this._cache.get('isWebWorker');
88
- }
89
-
90
- get isSharedWorker() {
91
- return this._cache.get('isSharedWorker');
92
- }
93
-
94
- get isDeno() {
95
- return this._cache.get('isDeno');
96
- }
97
-
98
- get isBun() {
99
- return this._cache.get('isBun');
100
- }
101
-
102
- get isServer() {
103
- return this.isNodeJS || this.isDeno || this.isBun;
104
- }
105
-
106
- get isClient() {
107
- return this.isBrowser || this.isWorker;
108
- }
109
-
110
- // WebRTC capability detection
111
- get hasWebRTC() {
112
- if (this.isBrowser) {
113
- return typeof RTCPeerConnection !== 'undefined' ||
114
- typeof webkitRTCPeerConnection !== 'undefined' ||
49
+ }
50
+
51
+ _detectServiceWorker() {
52
+ return typeof globalThis.ServiceWorkerGlobalScope !== 'undefined' &&
53
+ typeof self !== 'undefined' &&
54
+ self instanceof globalThis.ServiceWorkerGlobalScope;
55
+ }
56
+
57
+ _detectWebWorker() {
58
+ return typeof globalThis.DedicatedWorkerGlobalScope !== 'undefined' &&
59
+ typeof self !== 'undefined' &&
60
+ self instanceof globalThis.DedicatedWorkerGlobalScope;
61
+ }
62
+
63
+ _detectSharedWorker() {
64
+ return typeof globalThis.SharedWorkerGlobalScope !== 'undefined' &&
65
+ typeof self !== 'undefined' &&
66
+ self instanceof globalThis.SharedWorkerGlobalScope;
67
+ }
68
+
69
+ // Public getters
70
+ get isBrowser() {
71
+ return this._cache.get('isBrowser');
72
+ }
73
+
74
+ get isNodeJS() {
75
+ return this._cache.get('isNodeJS');
76
+ }
77
+
78
+ get isWorker() {
79
+ return this._cache.get('isWorker');
80
+ }
81
+
82
+ get isServiceWorker() {
83
+ return this._cache.get('isServiceWorker');
84
+ }
85
+
86
+ get isWebWorker() {
87
+ return this._cache.get('isWebWorker');
88
+ }
89
+
90
+ get isSharedWorker() {
91
+ return this._cache.get('isSharedWorker');
92
+ }
93
+
94
+ get isDeno() {
95
+ return this._cache.get('isDeno');
96
+ }
97
+
98
+ get isBun() {
99
+ return this._cache.get('isBun');
100
+ }
101
+
102
+ get isServer() {
103
+ return this.isNodeJS || this.isDeno || this.isBun;
104
+ }
105
+
106
+ get isClient() {
107
+ return this.isBrowser || this.isWorker;
108
+ }
109
+
110
+ // WebRTC capability detection
111
+ get hasWebRTC() {
112
+ if (this.isBrowser) {
113
+ return typeof RTCPeerConnection !== 'undefined' ||
114
+ typeof webkitRTCPeerConnection !== 'undefined' ||
115
115
  typeof mozRTCPeerConnection !== 'undefined';
116
- }
117
- if (this.isNodeJS) {
118
- // Check for Node.js WebRTC implementations or globally injected WebRTC
119
- return typeof global !== 'undefined' &&
120
- typeof global.RTCPeerConnection !== 'undefined' ||
116
+ }
117
+ if (this.isNodeJS) {
118
+ // Check for Node.js WebRTC implementations or globally injected WebRTC
119
+ return (typeof global !== 'undefined' &&
120
+ typeof global.RTCPeerConnection !== 'undefined') ||
121
121
  typeof RTCPeerConnection !== 'undefined';
122
- }
123
- return false;
124
122
  }
123
+ return false;
124
+ }
125
125
 
126
- get hasDataChannel() {
127
- return this.hasWebRTC && this.isBrowser;
128
- }
126
+ get hasDataChannel() {
127
+ return this.hasWebRTC && this.isBrowser;
128
+ }
129
129
 
130
- get hasGetUserMedia() {
131
- if (!this.isBrowser) return false;
132
- return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) ||
133
- !!(navigator.getUserMedia ||
134
- navigator.webkitGetUserMedia ||
130
+ get hasGetUserMedia() {
131
+ if (!this.isBrowser) return false;
132
+ return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) ||
133
+ !!(navigator.getUserMedia ||
134
+ navigator.webkitGetUserMedia ||
135
135
  navigator.mozGetUserMedia ||
136
136
  navigator.msGetUserMedia);
137
- }
138
-
139
- // WebSocket capability detection
140
- get hasWebSocket() {
141
- if (this.isBrowser || this.isWorker) {
142
- return typeof WebSocket !== 'undefined';
143
- }
144
- if (this.isNodeJS) {
145
- // Check for globally injected WebSocket first
146
- if (typeof global !== 'undefined' && typeof global.WebSocket !== 'undefined') {
147
- return true;
148
- }
149
- if (typeof WebSocket !== 'undefined') {
150
- return true;
151
- }
152
-
153
- try {
154
- // Try ES module import first
155
- if (typeof require !== 'undefined') {
156
- require.resolve('ws');
157
- return true;
158
- } else {
159
- // In ES modules, we can't easily check if a package is available
160
- // without actually importing it, so we'll assume it might be available
161
- return false; // Conservative approach
162
- }
163
- } catch (e) {
164
- return false;
165
- }
137
+ }
138
+
139
+ // WebSocket capability detection
140
+ get hasWebSocket() {
141
+ if (this.isBrowser || this.isWorker) {
142
+ return typeof WebSocket !== 'undefined';
143
+ }
144
+ if (this.isNodeJS) {
145
+ // Check for globally injected WebSocket first
146
+ if (typeof global !== 'undefined' && typeof global.WebSocket !== 'undefined') {
147
+ return true;
148
+ }
149
+ if (typeof WebSocket !== 'undefined') {
150
+ return true;
151
+ }
152
+
153
+ try {
154
+ // Try ES module import first
155
+ if (typeof require !== 'undefined') {
156
+ require.resolve('ws');
157
+ return true;
158
+ } else {
159
+ // In ES modules, we can't easily check if a package is available
160
+ // without actually importing it, so we'll assume it might be available
161
+ return false; // Conservative approach
166
162
  }
163
+ } catch (e) {
167
164
  return false;
168
- }
169
-
170
- // Storage capability detection
171
- get hasLocalStorage() {
172
- if (!this.isBrowser) return false;
173
- try {
174
- const test = '__storage_test__';
175
- localStorage.setItem(test, test);
176
- localStorage.removeItem(test);
177
- return true;
178
- } catch (e) {
179
- return false;
180
- }
181
- }
182
-
183
- get hasSessionStorage() {
184
- if (!this.isBrowser) return false;
185
- try {
186
- const test = '__storage_test__';
187
- sessionStorage.setItem(test, test);
188
- sessionStorage.removeItem(test);
189
- return true;
190
- } catch (e) {
191
- return false;
192
- }
193
- }
194
-
195
- get hasIndexedDB() {
196
- if (!this.isBrowser) return false;
197
- return typeof indexedDB !== 'undefined';
198
- }
199
-
200
- get hasCookies() {
201
- if (!this.isBrowser) return false;
202
- return typeof document !== 'undefined' &&
165
+ }
166
+ }
167
+ return false;
168
+ }
169
+
170
+ // Storage capability detection
171
+ get hasLocalStorage() {
172
+ if (!this.isBrowser) return false;
173
+ try {
174
+ const test = '__storage_test__';
175
+ localStorage.setItem(test, test);
176
+ localStorage.removeItem(test);
177
+ return true;
178
+ } catch (e) {
179
+ return false;
180
+ }
181
+ }
182
+
183
+ get hasSessionStorage() {
184
+ if (!this.isBrowser) return false;
185
+ try {
186
+ const test = '__storage_test__';
187
+ sessionStorage.setItem(test, test);
188
+ sessionStorage.removeItem(test);
189
+ return true;
190
+ } catch (e) {
191
+ return false;
192
+ }
193
+ }
194
+
195
+ get hasIndexedDB() {
196
+ if (!this.isBrowser) return false;
197
+ return typeof indexedDB !== 'undefined';
198
+ }
199
+
200
+ get hasCookies() {
201
+ if (!this.isBrowser) return false;
202
+ return typeof document !== 'undefined' &&
203
203
  typeof document.cookie === 'string';
204
- }
204
+ }
205
205
 
206
- // Network and connectivity detection
207
- get hasNetworkInformation() {
208
- if (!this.isBrowser) return false;
209
- return typeof navigator !== 'undefined' &&
206
+ // Network and connectivity detection
207
+ get hasNetworkInformation() {
208
+ if (!this.isBrowser) return false;
209
+ return typeof navigator !== 'undefined' &&
210
210
  'connection' in navigator;
211
- }
211
+ }
212
212
 
213
- get isOnline() {
214
- if (this.isBrowser) {
215
- return typeof navigator !== 'undefined' ? navigator.onLine : true;
216
- }
217
- return true; // Assume online for server environments
213
+ get isOnline() {
214
+ if (this.isBrowser) {
215
+ return typeof navigator !== 'undefined' ? navigator.onLine : true;
218
216
  }
217
+ return true; // Assume online for server environments
218
+ }
219
219
 
220
- get networkType() {
221
- if (this.hasNetworkInformation) {
222
- return navigator.connection.effectiveType || 'unknown';
223
- }
224
- return 'unknown';
220
+ get networkType() {
221
+ if (this.hasNetworkInformation) {
222
+ return navigator.connection.effectiveType || 'unknown';
225
223
  }
224
+ return 'unknown';
225
+ }
226
226
 
227
- // Crypto capabilities
228
- get hasCrypto() {
229
- if (this.isBrowser || this.isWorker) {
230
- return typeof crypto !== 'undefined' &&
227
+ // Crypto capabilities
228
+ get hasCrypto() {
229
+ if (this.isBrowser || this.isWorker) {
230
+ return typeof crypto !== 'undefined' &&
231
231
  typeof crypto.subtle !== 'undefined';
232
+ }
233
+ if (this.isNodeJS) {
234
+ try {
235
+ if (typeof require !== 'undefined') {
236
+ require('crypto');
237
+ return true;
238
+ } else {
239
+ // In ES modules, crypto is a built-in Node.js module
240
+ return typeof process !== 'undefined' && process.versions.node;
232
241
  }
233
- if (this.isNodeJS) {
234
- try {
235
- if (typeof require !== 'undefined') {
236
- require('crypto');
237
- return true;
238
- } else {
239
- // In ES modules, crypto is a built-in Node.js module
240
- return typeof process !== 'undefined' && process.versions.node;
241
- }
242
- } catch (e) {
243
- return false;
244
- }
245
- }
242
+ } catch (e) {
246
243
  return false;
244
+ }
247
245
  }
246
+ return false;
247
+ }
248
248
 
249
- get hasRandomValues() {
250
- if (this.isBrowser || this.isWorker) {
251
- return typeof crypto !== 'undefined' &&
249
+ get hasRandomValues() {
250
+ if (this.isBrowser || this.isWorker) {
251
+ return typeof crypto !== 'undefined' &&
252
252
  typeof crypto.getRandomValues === 'function';
253
+ }
254
+ if (this.isNodeJS) {
255
+ try {
256
+ if (typeof require !== 'undefined') {
257
+ const crypto = require('crypto');
258
+ return typeof crypto.randomBytes === 'function';
259
+ } else {
260
+ // In ES modules, crypto is a built-in Node.js module
261
+ return typeof process !== 'undefined' && process.versions.node;
253
262
  }
254
- if (this.isNodeJS) {
255
- try {
256
- if (typeof require !== 'undefined') {
257
- const crypto = require('crypto');
258
- return typeof crypto.randomBytes === 'function';
259
- } else {
260
- // In ES modules, crypto is a built-in Node.js module
261
- return typeof process !== 'undefined' && process.versions.node;
262
- }
263
- } catch (e) {
264
- return false;
265
- }
266
- }
263
+ } catch (e) {
267
264
  return false;
265
+ }
268
266
  }
267
+ return false;
268
+ }
269
269
 
270
- // Performance and timing
271
- get hasPerformanceNow() {
272
- return typeof performance !== 'undefined' &&
270
+ // Performance and timing
271
+ get hasPerformanceNow() {
272
+ return typeof performance !== 'undefined' &&
273
273
  typeof performance.now === 'function';
274
- }
274
+ }
275
275
 
276
- get hasHighResolutionTime() {
277
- if (this.isNodeJS) {
278
- return typeof process.hrtime === 'function' ||
276
+ get hasHighResolutionTime() {
277
+ if (this.isNodeJS) {
278
+ return typeof process.hrtime === 'function' ||
279
279
  typeof process.hrtime.bigint === 'function';
280
- }
281
- return this.hasPerformanceNow;
282
280
  }
281
+ return this.hasPerformanceNow;
282
+ }
283
283
 
284
- // Browser-specific detection
285
- getBrowserInfo() {
286
- if (!this.isBrowser) return null;
287
-
288
- const userAgent = navigator.userAgent;
289
- const browsers = {
290
- chrome: /Chrome\/(\d+)/.exec(userAgent),
291
- firefox: /Firefox\/(\d+)/.exec(userAgent),
292
- safari: /Safari\/(\d+)/.exec(userAgent) && !/Chrome/.test(userAgent),
293
- edge: /Edge\/(\d+)/.exec(userAgent),
294
- ie: /MSIE (\d+)/.exec(userAgent) || /Trident.*rv:(\d+)/.exec(userAgent)
295
- };
296
-
297
- for (const [browser, match] of Object.entries(browsers)) {
298
- if (match) {
299
- return {
300
- name: browser,
301
- version: match[1] || 'unknown'
302
- };
303
- }
304
- }
284
+ // Browser-specific detection
285
+ getBrowserInfo() {
286
+ if (!this.isBrowser) return null;
305
287
 
306
- return { name: 'unknown', version: 'unknown' };
307
- }
288
+ const userAgent = navigator.userAgent;
289
+ const browsers = {
290
+ chrome: /Chrome\/(\d+)/.exec(userAgent),
291
+ firefox: /Firefox\/(\d+)/.exec(userAgent),
292
+ safari: /Safari\/(\d+)/.exec(userAgent) && !/Chrome/.test(userAgent),
293
+ edge: /Edge\/(\d+)/.exec(userAgent),
294
+ ie: /MSIE (\d+)/.exec(userAgent) || /Trident.*rv:(\d+)/.exec(userAgent)
295
+ };
308
296
 
309
- // Node.js-specific detection
310
- getNodeInfo() {
311
- if (!this.isNodeJS) return null;
312
-
297
+ for (const [browser, match] of Object.entries(browsers)) {
298
+ if (match) {
313
299
  return {
314
- version: process.version,
315
- platform: process.platform,
316
- arch: process.arch,
317
- versions: process.versions
318
- };
319
- }
320
-
321
- // Device and platform detection
322
- getPlatformInfo() {
323
- if (this.isBrowser) {
324
- return {
325
- userAgent: navigator.userAgent,
326
- platform: navigator.platform,
327
- language: navigator.language,
328
- languages: navigator.languages || [navigator.language],
329
- cookieEnabled: navigator.cookieEnabled,
330
- onLine: navigator.onLine,
331
- hardwareConcurrency: navigator.hardwareConcurrency || 1
332
- };
333
- }
334
-
335
- if (this.isNodeJS) {
336
- return this.getNodeInfo();
337
- }
338
-
339
- return null;
340
- }
341
-
342
- // Feature detection for specific APIs
343
- hasFeature(feature) {
344
- const features = {
345
- // WebRTC
346
- 'webrtc': () => this.hasWebRTC,
347
- 'datachannel': () => this.hasDataChannel,
348
- 'getusermedia': () => this.hasGetUserMedia,
349
-
350
- // WebSocket
351
- 'websocket': () => this.hasWebSocket,
352
-
353
- // Storage
354
- 'localstorage': () => this.hasLocalStorage,
355
- 'sessionstorage': () => this.hasSessionStorage,
356
- 'indexeddb': () => this.hasIndexedDB,
357
- 'cookies': () => this.hasCookies,
358
-
359
- // Crypto
360
- 'crypto': () => this.hasCrypto,
361
- 'randomvalues': () => this.hasRandomValues,
362
-
363
- // Performance
364
- 'performance': () => this.hasPerformanceNow,
365
- 'hrtime': () => this.hasHighResolutionTime,
366
-
367
- // Network
368
- 'networkinfo': () => this.hasNetworkInformation,
369
- 'online': () => this.isOnline,
370
-
371
- // Workers
372
- 'webworker': () => typeof Worker !== 'undefined',
373
- 'serviceworker': () => typeof navigator !== 'undefined' && 'serviceWorker' in navigator,
374
- 'sharedworker': () => typeof SharedWorker !== 'undefined'
300
+ name: browser,
301
+ version: match[1] || 'unknown'
375
302
  };
376
-
377
- const featureCheck = features[feature.toLowerCase()];
378
- return featureCheck ? featureCheck() : false;
379
- }
380
-
381
- // Get comprehensive environment report
382
- getEnvironmentReport() {
383
- return {
384
- runtime: {
385
- isBrowser: this.isBrowser,
386
- isNodeJS: this.isNodeJS,
387
- isWorker: this.isWorker,
388
- isServiceWorker: this.isServiceWorker,
389
- isWebWorker: this.isWebWorker,
390
- isSharedWorker: this.isSharedWorker,
391
- isDeno: this.isDeno,
392
- isBun: this.isBun,
393
- isServer: this.isServer,
394
- isClient: this.isClient
395
- },
396
- capabilities: {
397
- webrtc: this.hasWebRTC,
398
- dataChannel: this.hasDataChannel,
399
- getUserMedia: this.hasGetUserMedia,
400
- webSocket: this.hasWebSocket,
401
- localStorage: this.hasLocalStorage,
402
- sessionStorage: this.hasSessionStorage,
403
- indexedDB: this.hasIndexedDB,
404
- cookies: this.hasCookies,
405
- crypto: this.hasCrypto,
406
- randomValues: this.hasRandomValues,
407
- performance: this.hasPerformanceNow,
408
- networkInfo: this.hasNetworkInformation
409
- },
410
- platform: this.getPlatformInfo(),
411
- browser: this.getBrowserInfo(),
412
- node: this.getNodeInfo(),
413
- network: {
414
- online: this.isOnline,
415
- type: this.networkType
416
- }
417
- };
418
- }
419
-
420
- // Static method for quick environment check
421
- static detect() {
422
- return new EnvironmentDetector();
423
- }
424
-
425
- // Static method for single feature check
426
- static hasFeature(feature) {
427
- const detector = new EnvironmentDetector();
428
- return detector.hasFeature(feature);
429
- }
303
+ }
304
+ }
305
+
306
+ return { name: 'unknown', version: 'unknown' };
307
+ }
308
+
309
+ // Node.js-specific detection
310
+ getNodeInfo() {
311
+ if (!this.isNodeJS) return null;
312
+
313
+ return {
314
+ version: process.version,
315
+ platform: process.platform,
316
+ arch: process.arch,
317
+ versions: process.versions
318
+ };
319
+ }
320
+
321
+ // Device and platform detection
322
+ getPlatformInfo() {
323
+ if (this.isBrowser) {
324
+ return {
325
+ userAgent: navigator.userAgent,
326
+ platform: navigator.platform,
327
+ language: navigator.language,
328
+ languages: navigator.languages || [navigator.language],
329
+ cookieEnabled: navigator.cookieEnabled,
330
+ onLine: navigator.onLine,
331
+ hardwareConcurrency: navigator.hardwareConcurrency || 1
332
+ };
333
+ }
334
+
335
+ if (this.isNodeJS) {
336
+ return this.getNodeInfo();
337
+ }
338
+
339
+ return null;
340
+ }
341
+
342
+ // Feature detection for specific APIs
343
+ hasFeature(feature) {
344
+ const features = {
345
+ // WebRTC
346
+ webrtc: () => this.hasWebRTC,
347
+ datachannel: () => this.hasDataChannel,
348
+ getusermedia: () => this.hasGetUserMedia,
349
+
350
+ // WebSocket
351
+ websocket: () => this.hasWebSocket,
352
+
353
+ // Storage
354
+ localstorage: () => this.hasLocalStorage,
355
+ sessionstorage: () => this.hasSessionStorage,
356
+ indexeddb: () => this.hasIndexedDB,
357
+ cookies: () => this.hasCookies,
358
+
359
+ // Crypto
360
+ crypto: () => this.hasCrypto,
361
+ randomvalues: () => this.hasRandomValues,
362
+
363
+ // Performance
364
+ performance: () => this.hasPerformanceNow,
365
+ hrtime: () => this.hasHighResolutionTime,
366
+
367
+ // Network
368
+ networkinfo: () => this.hasNetworkInformation,
369
+ online: () => this.isOnline,
370
+
371
+ // Workers
372
+ webworker: () => typeof Worker !== 'undefined',
373
+ serviceworker: () => typeof navigator !== 'undefined' && 'serviceWorker' in navigator,
374
+ sharedworker: () => typeof SharedWorker !== 'undefined'
375
+ };
376
+
377
+ const featureCheck = features[feature.toLowerCase()];
378
+ return featureCheck ? featureCheck() : false;
379
+ }
380
+
381
+ // Get comprehensive environment report
382
+ getEnvironmentReport() {
383
+ return {
384
+ runtime: {
385
+ isBrowser: this.isBrowser,
386
+ isNodeJS: this.isNodeJS,
387
+ isWorker: this.isWorker,
388
+ isServiceWorker: this.isServiceWorker,
389
+ isWebWorker: this.isWebWorker,
390
+ isSharedWorker: this.isSharedWorker,
391
+ isDeno: this.isDeno,
392
+ isBun: this.isBun,
393
+ isServer: this.isServer,
394
+ isClient: this.isClient
395
+ },
396
+ capabilities: {
397
+ webrtc: this.hasWebRTC,
398
+ dataChannel: this.hasDataChannel,
399
+ getUserMedia: this.hasGetUserMedia,
400
+ webSocket: this.hasWebSocket,
401
+ localStorage: this.hasLocalStorage,
402
+ sessionStorage: this.hasSessionStorage,
403
+ indexedDB: this.hasIndexedDB,
404
+ cookies: this.hasCookies,
405
+ crypto: this.hasCrypto,
406
+ randomValues: this.hasRandomValues,
407
+ performance: this.hasPerformanceNow,
408
+ networkInfo: this.hasNetworkInformation
409
+ },
410
+ platform: this.getPlatformInfo(),
411
+ browser: this.getBrowserInfo(),
412
+ node: this.getNodeInfo(),
413
+ network: {
414
+ online: this.isOnline,
415
+ type: this.networkType
416
+ }
417
+ };
418
+ }
419
+
420
+ // Static method for quick environment check
421
+ static detect() {
422
+ return new EnvironmentDetector();
423
+ }
424
+
425
+ // Static method for single feature check
426
+ static hasFeature(feature) {
427
+ const detector = new EnvironmentDetector();
428
+ return detector.hasFeature(feature);
429
+ }
430
430
  }
431
431
 
432
432
  // Export singleton instance for convenience