UNPKG

jodit

Version:

Jodit is awesome and usefully wysiwyg editor with filebrowser

52 lines (45 loc) 1.68 kB
/*! * Jodit Editor (https://xdsoft.net/jodit/) * Licensed under GNU General Public License version 2 or later or a commercial license or MIT; * For GPL see LICENSE-GPL.txt in the project root for license information. * For MIT see LICENSE-MIT.txt in the project root for license information. * For commercial licenses see https://xdsoft.net/jodit/commercial/ * Copyright (c) 2013-2019 Valeriy Chupurnov. All rights reserved. https://xdsoft.net */ /** * Module returns method that is used to determine the browser * @params {Object} parent main Jodit object * @example * ```javascript * console.log(Jodit.modules.Helpers.browser('mse')); * console.log(Jodit.modules.Helpers.browser('chrome')); * console.log($Jodit.modules.Helpers.browser('opera')); * console.log(Jodit.modules.Helpers.browser('firefox')); * console.log(Jodit.modules.Helpers.browser('mse') && Jodit.modules.Helpers.browser('version') > 10); * ``` */ export const browser = (browser: string): boolean | string => { const ua: string = navigator.userAgent.toLowerCase(), match: any = /(firefox)[\s\/]([\w.]+)/.exec(ua) || /(chrome)[\s\/]([\w.]+)/.exec(ua) || /(webkit)[\s\/]([\w.]+)/.exec(ua) || /(opera)(?:.*version)[\s\/]([\w.]+)/.exec(ua) || /(msie)[\s]([\w.]+)/.exec(ua) || /(trident)\/([\w.]+)/.exec(ua) || ua.indexOf('compatible') < 0 || []; if (browser === 'version') { return match[2]; } if (browser === 'webkit') { return match[1] === 'chrome' || match[1] === 'webkit'; } if (browser === 'ff') { return match[1] === 'firefox'; } if (browser === 'msie') { return match[1] === 'trident' || match[1] === 'msie'; } return match[1] === browser; };