Skip to main content

common

Small environment and user-agent checks used to detect whether code is running in a browser, on mobile, and what language/agent the browser reports.

Import: @rtorcato/browser-common/common

📖 MDN: Navigator

Example

import {
isBrowser,
getUserAgent,
isMobile,
getBrowserLanguage,
} from '@rtorcato/browser-common/common'

if (isBrowser) {
console.log(getUserAgent(), isMobile(), getBrowserLanguage())
}

Exports

  • isBrowsertrue if running in a browser environment
  • getUserAgent() — the navigator.userAgent string, or undefined
  • isMobile()true if the user agent matches a mobile device
  • getBrowserLanguage() — the navigator.language string, or undefined

See the API reference for full signatures.