當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript detect-browser.detect函數代碼示例

本文整理匯總了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} (&lt; ${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} (&lt; ${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} (&lt; ${SUPPORTED_CHROME_VERSION})`;
      }
      return null;
    case 'ie':
      return `${prefix} Internet Explorer`;
  }
  console.warn('unknown browser detected', info, 'assuming fine...');
  return null;
}
開發者ID:Caleydo,項目名稱:lineup.js,代碼行數:31,代碼來源:browser.ts

示例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;
 }
開發者ID:IlsooByun,項目名稱:ceph,代碼行數:15,代碼來源:about.component.ts

示例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(
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:detect-browser-tests.ts

示例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);
};
開發者ID:beqom,項目名稱:clarity,代碼行數:26,代碼來源:tests.helpers.ts


注:本文中的detect-browser.detect函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。