peerpigeon 0.0.5 → 0.0.7

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,502 @@
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
+ this._cache.set('isNativeScript', this._detectNativeScript());
22
+ }
23
+
24
+ // Primary environment detection
25
+ _detectBrowser() {
26
+ return typeof window !== 'undefined' &&
27
+ typeof document !== 'undefined' &&
27
28
  typeof navigator !== 'undefined';
28
- }
29
+ }
29
30
 
30
- _detectNodeJS() {
31
- return typeof process !== 'undefined' &&
32
- process.versions != null &&
31
+ _detectNodeJS() {
32
+ return typeof process !== 'undefined' &&
33
+ process.versions != null &&
33
34
  process.versions.node != null;
34
- }
35
-
36
- _detectDeno() {
37
- return typeof Deno !== 'undefined';
38
- }
39
-
40
- _detectBun() {
41
- return typeof Bun !== 'undefined';
42
- }
43
-
44
- _detectWorker() {
45
- return typeof importScripts !== 'undefined' ||
46
- this._detectServiceWorker() ||
47
- this._detectWebWorker() ||
35
+ }
36
+
37
+ _detectDeno() {
38
+ return typeof Deno !== 'undefined';
39
+ }
40
+
41
+ _detectBun() {
42
+ return typeof Bun !== 'undefined';
43
+ }
44
+
45
+ _detectNativeScript() {
46
+ return typeof global !== 'undefined' &&
47
+ ((typeof global.NativeScriptGlobals !== 'undefined') ||
48
+ (typeof global.__ANDROID__ !== 'undefined') ||
49
+ (typeof global.__IOS__ !== 'undefined') ||
50
+ (typeof global.__VISIONOS__ !== 'undefined') ||
51
+ (typeof global.loadModule === 'function' && typeof global.registerModule === 'function'));
52
+ }
53
+
54
+ _detectWorker() {
55
+ return typeof importScripts !== 'undefined' ||
56
+ this._detectServiceWorker() ||
57
+ this._detectWebWorker() ||
48
58
  this._detectSharedWorker();
59
+ }
60
+
61
+ _detectServiceWorker() {
62
+ return typeof globalThis.ServiceWorkerGlobalScope !== 'undefined' &&
63
+ typeof self !== 'undefined' &&
64
+ self instanceof globalThis.ServiceWorkerGlobalScope;
65
+ }
66
+
67
+ _detectWebWorker() {
68
+ return typeof globalThis.DedicatedWorkerGlobalScope !== 'undefined' &&
69
+ typeof self !== 'undefined' &&
70
+ self instanceof globalThis.DedicatedWorkerGlobalScope;
71
+ }
72
+
73
+ _detectSharedWorker() {
74
+ return typeof globalThis.SharedWorkerGlobalScope !== 'undefined' &&
75
+ typeof self !== 'undefined' &&
76
+ self instanceof globalThis.SharedWorkerGlobalScope;
77
+ }
78
+
79
+ // Public getters
80
+ get isBrowser() {
81
+ return this._cache.get('isBrowser');
82
+ }
83
+
84
+ get isNodeJS() {
85
+ return this._cache.get('isNodeJS');
86
+ }
87
+
88
+ get isWorker() {
89
+ return this._cache.get('isWorker');
90
+ }
91
+
92
+ get isServiceWorker() {
93
+ return this._cache.get('isServiceWorker');
94
+ }
95
+
96
+ get isWebWorker() {
97
+ return this._cache.get('isWebWorker');
98
+ }
99
+
100
+ get isSharedWorker() {
101
+ return this._cache.get('isSharedWorker');
102
+ }
103
+
104
+ get isDeno() {
105
+ return this._cache.get('isDeno');
106
+ }
107
+
108
+ get isBun() {
109
+ return this._cache.get('isBun');
110
+ }
111
+
112
+ get isNativeScript() {
113
+ return this._cache.get('isNativeScript');
114
+ }
115
+
116
+ get isServer() {
117
+ return this.isNodeJS || this.isDeno || this.isBun;
118
+ }
119
+
120
+ get isClient() {
121
+ return this.isBrowser || this.isWorker || this.isNativeScript;
122
+ }
123
+
124
+ // WebRTC capability detection
125
+ get hasWebRTC() {
126
+ if (this.isBrowser) {
127
+ return typeof RTCPeerConnection !== 'undefined' ||
128
+ typeof webkitRTCPeerConnection !== 'undefined' ||
129
+ typeof mozRTCPeerConnection !== 'undefined';
49
130
  }
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;
131
+ if (this.isNodeJS) {
132
+ // Check for Node.js WebRTC implementations or globally injected WebRTC
133
+ return (typeof global !== 'undefined' &&
134
+ typeof global.RTCPeerConnection !== 'undefined') ||
135
+ typeof RTCPeerConnection !== 'undefined';
108
136
  }
109
-
110
- // WebRTC capability detection
111
- get hasWebRTC() {
112
- if (this.isBrowser) {
113
- return typeof RTCPeerConnection !== 'undefined' ||
114
- typeof webkitRTCPeerConnection !== 'undefined' ||
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' ||
137
+ if (this.isNativeScript) {
138
+ // NativeScript can access native WebRTC implementations through native modules
139
+ // Check for globally injected WebRTC first
140
+ return (typeof global !== 'undefined' &&
141
+ typeof global.RTCPeerConnection !== 'undefined') ||
121
142
  typeof RTCPeerConnection !== 'undefined';
122
- }
123
- return false;
124
143
  }
144
+ return false;
145
+ }
125
146
 
126
- get hasDataChannel() {
127
- return this.hasWebRTC && this.isBrowser;
128
- }
147
+ get hasDataChannel() {
148
+ return this.hasWebRTC && (this.isBrowser || this.isNativeScript);
149
+ }
129
150
 
130
- get hasGetUserMedia() {
131
- if (!this.isBrowser) return false;
132
- return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) ||
133
- !!(navigator.getUserMedia ||
134
- navigator.webkitGetUserMedia ||
151
+ get hasGetUserMedia() {
152
+ if (!this.isBrowser && !this.isNativeScript) return false;
153
+ return !!(navigator && navigator.mediaDevices && navigator.mediaDevices.getUserMedia) ||
154
+ !!(navigator && (navigator.getUserMedia ||
155
+ navigator.webkitGetUserMedia ||
135
156
  navigator.mozGetUserMedia ||
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
- }
157
+ navigator.msGetUserMedia));
158
+ }
159
+
160
+ // WebSocket capability detection
161
+ get hasWebSocket() {
162
+ if (this.isBrowser || this.isWorker) {
163
+ return typeof WebSocket !== 'undefined';
164
+ }
165
+ if (this.isNodeJS) {
166
+ // Check for globally injected WebSocket first
167
+ if (typeof global !== 'undefined' && typeof global.WebSocket !== 'undefined') {
168
+ return true;
169
+ }
170
+ if (typeof WebSocket !== 'undefined') {
171
+ return true;
172
+ }
173
+
174
+ try {
175
+ // Try ES module import first
176
+ if (typeof require !== 'undefined') {
177
+ require.resolve('ws');
178
+ return true;
179
+ } else {
180
+ // In ES modules, we can't easily check if a package is available
181
+ // without actually importing it, so we'll assume it might be available
182
+ return false; // Conservative approach
166
183
  }
184
+ } catch (e) {
167
185
  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' &&
186
+ }
187
+ }
188
+ if (this.isNativeScript) {
189
+ // NativeScript has WebSocket support through global injection or native modules
190
+ return typeof WebSocket !== 'undefined' ||
191
+ (typeof global !== 'undefined' && typeof global.WebSocket !== 'undefined');
192
+ }
193
+ return false;
194
+ }
195
+
196
+ // Storage capability detection
197
+ get hasLocalStorage() {
198
+ if (!this.isBrowser && !this.isNativeScript) return false;
199
+ try {
200
+ const test = '__storage_test__';
201
+ localStorage.setItem(test, test);
202
+ localStorage.removeItem(test);
203
+ return true;
204
+ } catch (e) {
205
+ return false;
206
+ }
207
+ }
208
+
209
+ get hasSessionStorage() {
210
+ if (!this.isBrowser && !this.isNativeScript) return false;
211
+ try {
212
+ const test = '__storage_test__';
213
+ sessionStorage.setItem(test, test);
214
+ sessionStorage.removeItem(test);
215
+ return true;
216
+ } catch (e) {
217
+ return false;
218
+ }
219
+ }
220
+
221
+ get hasIndexedDB() {
222
+ if (!this.isBrowser) return false; // NativeScript doesn't typically have IndexedDB
223
+ return typeof indexedDB !== 'undefined';
224
+ }
225
+
226
+ get hasCookies() {
227
+ if (!this.isBrowser) return false; // NativeScript doesn't have cookies
228
+ return typeof document !== 'undefined' &&
203
229
  typeof document.cookie === 'string';
204
- }
230
+ }
205
231
 
206
- // Network and connectivity detection
207
- get hasNetworkInformation() {
208
- if (!this.isBrowser) return false;
209
- return typeof navigator !== 'undefined' &&
232
+ // Network and connectivity detection
233
+ get hasNetworkInformation() {
234
+ if (!this.isBrowser) return false;
235
+ return typeof navigator !== 'undefined' &&
210
236
  'connection' in navigator;
211
- }
237
+ }
212
238
 
213
- get isOnline() {
214
- if (this.isBrowser) {
215
- return typeof navigator !== 'undefined' ? navigator.onLine : true;
216
- }
217
- return true; // Assume online for server environments
239
+ get isOnline() {
240
+ if (this.isBrowser) {
241
+ return typeof navigator !== 'undefined' ? navigator.onLine : true;
218
242
  }
243
+ return true; // Assume online for server environments
244
+ }
219
245
 
220
- get networkType() {
221
- if (this.hasNetworkInformation) {
222
- return navigator.connection.effectiveType || 'unknown';
223
- }
224
- return 'unknown';
246
+ get networkType() {
247
+ if (this.hasNetworkInformation) {
248
+ return navigator.connection.effectiveType || 'unknown';
225
249
  }
250
+ return 'unknown';
251
+ }
226
252
 
227
- // Crypto capabilities
228
- get hasCrypto() {
229
- if (this.isBrowser || this.isWorker) {
230
- return typeof crypto !== 'undefined' &&
253
+ // Crypto capabilities
254
+ get hasCrypto() {
255
+ if (this.isBrowser || this.isWorker) {
256
+ return typeof crypto !== 'undefined' &&
231
257
  typeof crypto.subtle !== 'undefined';
258
+ }
259
+ if (this.isNodeJS) {
260
+ try {
261
+ if (typeof require !== 'undefined') {
262
+ require('crypto');
263
+ return true;
264
+ } else {
265
+ // In ES modules, crypto is a built-in Node.js module
266
+ return typeof process !== 'undefined' && process.versions.node;
232
267
  }
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
- }
268
+ } catch (e) {
246
269
  return false;
270
+ }
247
271
  }
272
+ if (this.isNativeScript) {
273
+ // NativeScript may have crypto through global polyfills or native modules
274
+ return (typeof crypto !== 'undefined' && typeof crypto.subtle !== 'undefined') ||
275
+ (typeof global !== 'undefined' && typeof global.crypto !== 'undefined');
276
+ }
277
+ return false;
278
+ }
248
279
 
249
- get hasRandomValues() {
250
- if (this.isBrowser || this.isWorker) {
251
- return typeof crypto !== 'undefined' &&
280
+ get hasRandomValues() {
281
+ if (this.isBrowser || this.isWorker) {
282
+ return typeof crypto !== 'undefined' &&
252
283
  typeof crypto.getRandomValues === 'function';
284
+ }
285
+ if (this.isNodeJS) {
286
+ try {
287
+ if (typeof require !== 'undefined') {
288
+ const crypto = require('crypto');
289
+ return typeof crypto.randomBytes === 'function';
290
+ } else {
291
+ // In ES modules, crypto is a built-in Node.js module
292
+ return typeof process !== 'undefined' && process.versions.node;
253
293
  }
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
- }
294
+ } catch (e) {
267
295
  return false;
296
+ }
268
297
  }
298
+ if (this.isNativeScript) {
299
+ // NativeScript may have crypto random values through global polyfills
300
+ return (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') ||
301
+ (typeof global !== 'undefined' &&
302
+ typeof global.crypto !== 'undefined' &&
303
+ typeof global.crypto.getRandomValues === 'function');
304
+ }
305
+ return false;
306
+ }
269
307
 
270
- // Performance and timing
271
- get hasPerformanceNow() {
272
- return typeof performance !== 'undefined' &&
308
+ // Performance and timing
309
+ get hasPerformanceNow() {
310
+ return typeof performance !== 'undefined' &&
273
311
  typeof performance.now === 'function';
274
- }
312
+ }
275
313
 
276
- get hasHighResolutionTime() {
277
- if (this.isNodeJS) {
278
- return typeof process.hrtime === 'function' ||
314
+ get hasHighResolutionTime() {
315
+ if (this.isNodeJS) {
316
+ return typeof process.hrtime === 'function' ||
279
317
  typeof process.hrtime.bigint === 'function';
280
- }
281
- return this.hasPerformanceNow;
282
- }
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
- }
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
318
  }
319
+ return this.hasPerformanceNow;
320
+ }
320
321
 
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
- }
322
+ // Browser-specific detection
323
+ getBrowserInfo() {
324
+ if (!this.isBrowser) return null;
341
325
 
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
- }
326
+ const userAgent = navigator.userAgent;
327
+ const browsers = {
328
+ chrome: /Chrome\/(\d+)/.exec(userAgent),
329
+ firefox: /Firefox\/(\d+)/.exec(userAgent),
330
+ safari: /Safari\/(\d+)/.exec(userAgent) && !/Chrome/.test(userAgent),
331
+ edge: /Edge\/(\d+)/.exec(userAgent),
332
+ ie: /MSIE (\d+)/.exec(userAgent) || /Trident.*rv:(\d+)/.exec(userAgent)
333
+ };
380
334
 
381
- // Get comprehensive environment report
382
- getEnvironmentReport() {
335
+ for (const [browser, match] of Object.entries(browsers)) {
336
+ if (match) {
383
337
  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
- }
338
+ name: browser,
339
+ version: match[1] || 'unknown'
417
340
  };
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
- }
341
+ }
342
+ }
343
+
344
+ return { name: 'unknown', version: 'unknown' };
345
+ }
346
+
347
+ // Node.js-specific detection
348
+ getNodeInfo() {
349
+ if (!this.isNodeJS) return null;
350
+
351
+ return {
352
+ version: process.version,
353
+ platform: process.platform,
354
+ arch: process.arch,
355
+ versions: process.versions
356
+ };
357
+ }
358
+
359
+ // NativeScript-specific detection
360
+ getNativeScriptInfo() {
361
+ if (!this.isNativeScript) return null;
362
+
363
+ const info = {
364
+ runtime: 'nativescript'
365
+ };
366
+
367
+ // Detect platform if globals are available
368
+ if (typeof global !== 'undefined') {
369
+ if (global.__ANDROID__) {
370
+ info.platform = 'android';
371
+ } else if (global.__IOS__) {
372
+ info.platform = 'ios';
373
+ } else if (global.__VISIONOS__) {
374
+ info.platform = 'visionos';
375
+ }
376
+
377
+ // Add additional NativeScript globals if available
378
+ if (global.NativeScriptGlobals) {
379
+ info.launched = global.NativeScriptGlobals.launched;
380
+ info.appInstanceReady = global.NativeScriptGlobals.appInstanceReady;
381
+ }
382
+ }
383
+
384
+ return info;
385
+ }
386
+
387
+ // Device and platform detection
388
+ getPlatformInfo() {
389
+ if (this.isBrowser) {
390
+ return {
391
+ userAgent: navigator.userAgent,
392
+ platform: navigator.platform,
393
+ language: navigator.language,
394
+ languages: navigator.languages || [navigator.language],
395
+ cookieEnabled: navigator.cookieEnabled,
396
+ onLine: navigator.onLine,
397
+ hardwareConcurrency: navigator.hardwareConcurrency || 1
398
+ };
399
+ }
400
+
401
+ if (this.isNodeJS) {
402
+ return this.getNodeInfo();
403
+ }
404
+
405
+ if (this.isNativeScript) {
406
+ return this.getNativeScriptInfo();
407
+ }
408
+
409
+ return null;
410
+ }
411
+
412
+ // Feature detection for specific APIs
413
+ hasFeature(feature) {
414
+ const features = {
415
+ // WebRTC
416
+ webrtc: () => this.hasWebRTC,
417
+ datachannel: () => this.hasDataChannel,
418
+ getusermedia: () => this.hasGetUserMedia,
419
+
420
+ // WebSocket
421
+ websocket: () => this.hasWebSocket,
422
+
423
+ // Storage
424
+ localstorage: () => this.hasLocalStorage,
425
+ sessionstorage: () => this.hasSessionStorage,
426
+ indexeddb: () => this.hasIndexedDB,
427
+ cookies: () => this.hasCookies,
428
+
429
+ // Crypto
430
+ crypto: () => this.hasCrypto,
431
+ randomvalues: () => this.hasRandomValues,
432
+
433
+ // Performance
434
+ performance: () => this.hasPerformanceNow,
435
+ hrtime: () => this.hasHighResolutionTime,
436
+
437
+ // Network
438
+ networkinfo: () => this.hasNetworkInformation,
439
+ online: () => this.isOnline,
440
+
441
+ // Workers
442
+ webworker: () => typeof Worker !== 'undefined',
443
+ serviceworker: () => typeof navigator !== 'undefined' && 'serviceWorker' in navigator,
444
+ sharedworker: () => typeof SharedWorker !== 'undefined'
445
+ };
446
+
447
+ const featureCheck = features[feature.toLowerCase()];
448
+ return featureCheck ? featureCheck() : false;
449
+ }
450
+
451
+ // Get comprehensive environment report
452
+ getEnvironmentReport() {
453
+ return {
454
+ runtime: {
455
+ isBrowser: this.isBrowser,
456
+ isNodeJS: this.isNodeJS,
457
+ isWorker: this.isWorker,
458
+ isServiceWorker: this.isServiceWorker,
459
+ isWebWorker: this.isWebWorker,
460
+ isSharedWorker: this.isSharedWorker,
461
+ isDeno: this.isDeno,
462
+ isBun: this.isBun,
463
+ isNativeScript: this.isNativeScript,
464
+ isServer: this.isServer,
465
+ isClient: this.isClient
466
+ },
467
+ capabilities: {
468
+ webrtc: this.hasWebRTC,
469
+ dataChannel: this.hasDataChannel,
470
+ getUserMedia: this.hasGetUserMedia,
471
+ webSocket: this.hasWebSocket,
472
+ localStorage: this.hasLocalStorage,
473
+ sessionStorage: this.hasSessionStorage,
474
+ indexedDB: this.hasIndexedDB,
475
+ cookies: this.hasCookies,
476
+ crypto: this.hasCrypto,
477
+ randomValues: this.hasRandomValues,
478
+ performance: this.hasPerformanceNow,
479
+ networkInfo: this.hasNetworkInformation
480
+ },
481
+ platform: this.getPlatformInfo(),
482
+ browser: this.getBrowserInfo(),
483
+ node: this.getNodeInfo(),
484
+ nativescript: this.getNativeScriptInfo(),
485
+ network: {
486
+ online: this.isOnline,
487
+ type: this.networkType
488
+ }
489
+ };
490
+ }
491
+
492
+ // Static method for quick environment check
493
+ static detect() {
494
+ return new EnvironmentDetector();
495
+ }
496
+
497
+ // Static method for single feature check
498
+ static hasFeature(feature) {
499
+ const detector = new EnvironmentDetector();
500
+ return detector.hasFeature(feature);
501
+ }
430
502
  }
431
503
 
432
504
  // Export singleton instance for convenience
@@ -436,6 +508,7 @@ export const environmentDetector = new EnvironmentDetector();
436
508
  export const isBrowser = () => environmentDetector.isBrowser;
437
509
  export const isNodeJS = () => environmentDetector.isNodeJS;
438
510
  export const isWorker = () => environmentDetector.isWorker;
511
+ export const isNativeScript = () => environmentDetector.isNativeScript;
439
512
  export const hasWebRTC = () => environmentDetector.hasWebRTC;
440
513
  export const hasWebSocket = () => environmentDetector.hasWebSocket;
441
514
  export const getEnvironmentReport = () => environmentDetector.getEnvironmentReport();