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
Example
import {
isBrowser,
getUserAgent,
isMobile,
getBrowserLanguage,
} from '@rtorcato/browser-common/common'
if (isBrowser) {
console.log(getUserAgent(), isMobile(), getBrowserLanguage())
}
Exports
isBrowser—trueif running in a browser environmentgetUserAgent()— thenavigator.userAgentstring, orundefinedisMobile()—trueif the user agent matches a mobile devicegetBrowserLanguage()— thenavigator.languagestring, orundefined
See the API reference for full signatures.