Skip to content

Commit

Permalink
feat: add compatibility with txiki.js (#1895)
Browse files Browse the repository at this point in the history
* feat: add compatibility with txiki.js
txiki.js is compatible with most of the browser api, but it does not have the document variable.

* style: run lint-fix

* fix: navigator undefined
  • Loading branch information
EmixamPP authored Jun 27, 2024
1 parent 0485ac7 commit 37b08c9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/is-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const isStandardBrowserEnv = () => {
return false
}

const isTxikijsEnv = () =>
typeof navigator !== 'undefined' && navigator.userAgent === 'txiki.js'

const isWebWorkerEnv = () =>
Boolean(
// eslint-disable-next-line no-restricted-globals
Expand All @@ -37,7 +40,10 @@ const isReactNativeEnv = () =>
typeof navigator !== 'undefined' && navigator.product === 'ReactNative'

const isBrowser =
isStandardBrowserEnv() || isWebWorkerEnv() || isReactNativeEnv()
isStandardBrowserEnv() ||
isWebWorkerEnv() ||
isReactNativeEnv() ||
isTxikijsEnv()

export const isWebWorker = isWebWorkerEnv()

Expand Down

0 comments on commit 37b08c9

Please sign in to comment.