import bowser from 'bowser' ; import filter from 'lodash/filter' ; import memoize from 'lodash/memoize' ; import keyBy from 'lodash/keyBy' ; const ChromeIcon = require ( 'url-loader!./icons/chrome.svg' ) ; const FirefoxIcon = require ( 'url-loader!./icons/firefox.svg' ) ; const EdgeIcon = require ( 'url-loader!./icons/edge.svg' ) ; const OperaIcon = require ( 'url-loader!./icons/opera.svg' ) ; const SafariIcon = require ( 'url-loader!./icons/safari-ios.svg' ) ; interface BrowserDetails { id : string ; downloadUrl : string ; icon : string ; isApplicable ? : boolean | ( ( ) => boolean ) ; } const _current = bowser ; export const recommendedBrowsers = [ { id : 'Chrome' , downloadUrl : 'https://google.com/chrome' , icon : ChromeIcon , } , { id : 'Firefox' , downloadUrl : 'https://getfirefox.com/' , icon : FirefoxIcon , } , { id : 'Opera' , downloadUrl : 'https://opera.com/' , icon : OperaIcon , } , { id : 'Microsoft Edge' , downloadUrl : 'https://www.microsoft.com/windows/microsoft-edge' , icon : EdgeIcon , isApplicable ( ) { return _current . windows && _current . osversion === '10' ; } , } , { id : 'Safari' , downloadUrl : 'https://www.apple.com/safari/' , icon : SafariIcon , isApplicable ( ) { return _current . mac ; } , } , ] ; export const browsersById = keyBy ( recommendedBrowsers , b => b . id ) ; export const currentBrowser = { id : _current . name as BrowserId , downloadUrl : browsersById [ _current . name ] ? browsersById [ _current . name ] . downloadUrl : '' , version : _current . version , } ; export const getApplicapleBrowsers = memoize ( ( excludeCurrentBrowser = true ) => filter ( recommendedBrowsers , ( browser ) => { if ( excludeCurrentBrowser && browser . id === currentBrowser . id ) { return false ; } if ( typeof browser . isApplicable === 'function' ) { return browser . isApplicable ( ) ; } else if ( typeof browser . isApplicable === 'boolean' ) { return browser . isApplicable ; } return true ; } ) ) ; export default recommendedBrowsers ;