本文整理汇总了TypeScript中detect-browser.detect函数的典型用法代码示例。如果您正苦于以下问题:TypeScript detect函数的具体用法?TypeScript detect怎么用?TypeScript detect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了detect函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getUnsupportedBrowserError
export function getUnsupportedBrowserError() {
const info = detect();
if (!info) {
return 'browser cannot be detected';
}
const prefix = `unsupported browser detected:`;
switch(info.name) {
case 'firefox':
const fVersion = parseInt(info.version.slice(0, info.version.indexOf('.')), 10);
if(fVersion <= SUPPORTED_FIREFOX_VERSION && fVersion !== 52) { // ESR
return `${prefix} Firefox ${info.version} (< ${SUPPORTED_FIREFOX_VERSION})`;
}
return null;
case 'edge':
const eVersion = parseInt(info.version.slice(0, info.version.indexOf('.')), 10);
if(eVersion <= SUPPORTED_EDGE_VERSION) {
return `${prefix} Edge ${info.version} (< ${SUPPORTED_EDGE_VERSION})`;
}
return null;
case 'chrome':
const cVersion = parseInt(info.version.slice(0, info.version.indexOf('.')), 10);
if(cVersion <= SUPPORTED_CHROME_VERSION) {
return `${prefix} Chrome ${info.version} (< ${SUPPORTED_CHROME_VERSION})`;
}
return null;
case 'ie':
return `${prefix} Internet Explorer`;
}
console.warn('unknown browser detected', info, 'assuming fine...');
return null;
}
示例2: setVariables
setVariables() {
const project = {} as any;
project.user = localStorage.getItem('dashboard_username');
project.role = 'user';
if (this.userPermission.read) {
this.userService.get(project.user).subscribe((data: any) => {
project.role = data.roles;
});
}
const browser = detect();
project.browserName = browser && browser.name ? browser.name : 'Not detected';
project.browserVersion = browser && browser.version ? browser.version : 'Not detected';
project.browserOS = browser && browser.os ? browser.os : 'Not detected';
return project;
}
示例3: detect
import { BrowserName, BrowserInfo, detect } from 'detect-browser';
const browser = detect();
if (browser) {
const name: string | undefined = browser.name;
const version: string | undefined = browser.version;
const os: string | undefined | null = browser.os;
const bot: true | undefined = browser.bot;
}
const browserInfos: BrowserInfo[] = [];
// Those that can happen when 'detect' hits on a browser
browserInfos.push(
{
name: "chrome",
version: "1.2.3",
os: null
}
);
browserInfos.push(
{
name: "edge",
version: "24.5.3",
os: "Sun OS"
}
);
browserInfos.push(
示例4: xit
import * as BrowserDetector from "detect-browser";
const browser = BrowserDetector.detect();
export const itIgnore = (browsers: string[], should: string, test: any, focus: boolean = false) => {
if (browsers.length && browsers.indexOf(browser.name) >= 0) {
return xit(should, test);
}
return (focus) ? fit(should, test) : it(should, test);
};
export const fitIgnore = (browsers: string[], should: string, test: any) => {
itIgnore(browsers, should, test, true);
}
export const describeIgnore = (browsers: string[], title: string, suite: any, focus: boolean = false) => {
if (browsers.length && browsers.indexOf(browser.name) >= 0) {
return xdescribe(title, suite);
}
return (focus) ? fdescribe(title, suite) : describe(title, suite);
};
export const fdescribeIgnore = (browsers: string[], title: string, suite: any) => {
describeIgnore(browsers, title, suite, true);
};