UNPKG

backendless

Version:

Backendless JavaScript SDK for Node.js and the browser

32 lines (23 loc) 736 B
import Utils from './utils' export function getUserAgent() { let ua = 'NodeJS' if (Utils.isBrowser) { const navigator = Utils.getWindowNavigator() ua = navigator.userAgent ? navigator.userAgent.toLowerCase() : 'hybrid-app' } const match = (/(chrome)[ \/]([\w.]+)/.exec(ua) || /(webkit)[ \/]([\w.]+)/.exec(ua) || /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || /(msie) ([\w.]+)/.exec(ua) || ua.indexOf('compatible') < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || []) const matched = { browser: match[1] || '', version: match[2] || '0' } const browser = {} if (matched.browser) { browser[matched.browser] = true browser.version = matched.version } return browser }