本文整理匯總了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);
};