当前位置: 首页>>代码示例>>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;未经允许,请勿转载。