Нема описа

runtime.js 806B

1234567891011121314151617181920212223242526
  1. export const JSRuntime = {
  2. browser: 'browser',
  3. bun: 'bun',
  4. deno: 'deno',
  5. node: 'node',
  6. workerd: 'workerd',
  7. }
  8. const isBun = !!globalThis.Bun || !!globalThis.process?.versions?.bun
  9. const isDeno = !!globalThis.Deno
  10. const isNode = globalThis.process?.release?.name === 'node'
  11. // eslint-disable-next-line n/no-unsupported-features/node-builtins
  12. const isWorkerd = globalThis.navigator?.userAgent === 'Cloudflare-Workers'
  13. // eslint-disable-next-line n/no-unsupported-features/node-builtins
  14. const isBrowser = !!globalThis.window && !!globalThis.navigator
  15. export const runtime = (() => {
  16. if (isBun) return JSRuntime.bun
  17. if (isDeno) return JSRuntime.deno
  18. if (isNode) return JSRuntime.node
  19. if (isWorkerd) return JSRuntime.workerd
  20. if (isBrowser) return JSRuntime.browser
  21. return 'unknown'
  22. })()