Comparing version 0.0.82 to 0.0.83
{ | ||
"name": "webdetta", | ||
"version": "0.0.82", | ||
"version": "0.0.83", | ||
"author": "Fedot Kriutchenko <fodyadev@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "", |
@@ -0,19 +1,35 @@ | ||
let globals; | ||
try { globals = globalThis; } | ||
catch (e) { globals = {}; } | ||
const get = (...path) => { | ||
const obj = globals; | ||
for (const k of path) { | ||
if (typeof obj != 'object' || obj == null) return null; | ||
obj = obj[k]; | ||
} | ||
return obj; | ||
} | ||
export default ( | ||
typeof window?.document != null | ||
get('window', 'document') != null | ||
? 'browser' : | ||
process?.versions?.node != null | ||
get('process', 'versions', 'node') != null | ||
? 'node' : | ||
get('self', 'constructor', 'name') === 'DedicatedWorkerGlobalScope' | ||
? 'webworker' : | ||
// https://github.com/jsdom/jsdom/issues/1537#issuecomment-229405327 | ||
window?.name === 'nodejs' || | ||
(navigator?.userAgent ?? '').includes('Node.js') || | ||
(navigator?.userAgent ?? '').includes('jsdom') | ||
? 'jsdom' : | ||
get('window', 'name') === 'nodejs' || | ||
['Node.js', 'jsdom'].some(d => | ||
String(get('navigator', 'userAgent') ?? '').includes(d) | ||
) ? 'jsdom' : | ||
Deno?.version?.deno != null | ||
get('Deno', 'version', 'deno') != null | ||
? 'deno' : | ||
// https://bun.sh/guides/util/detect-bun | ||
process?.versions?.bun != null | ||
get('process', 'versions', 'bun') != null | ||
? 'bun' : | ||
@@ -20,0 +36,0 @@ |
96429
2846