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


TypeScript ua-parser-js.UAParser類代碼示例

本文整理匯總了TypeScript中ua-parser-js.UAParser的典型用法代碼示例。如果您正苦於以下問題:TypeScript UAParser類的具體用法?TypeScript UAParser怎麽用?TypeScript UAParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UAParser類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: browserCapabilities

export function browserCapabilities(userAgent: string): Set<BrowserCapability> {
  const ua = new UAParser(userAgent);
  const capabilities = new Set<BrowserCapability>();
  const predicates = browserPredicates[ua.getBrowser().name || ''] || {};
  for (const capability of Object.keys(predicates) as BrowserCapability[]) {
    if (predicates[capability](ua)) {
      capabilities.add(capability);
    }
  }
  return capabilities;
}
開發者ID:MehdiRaash,項目名稱:tools,代碼行數:11,代碼來源:browser-capabilities.ts

示例2: getOS

export function getOS() {
  if (__DARWIN__) {
    // On macOS, OS.release() gives us the kernel version which isn't terribly
    // meaningful to any human being, so we'll parse the User Agent instead.
    // See https://github.com/desktop/desktop/issues/1130.
    const parser = new UAParser()
    const os = parser.getOS()
    return `${os.name} ${os.version}`
  } else if (__WIN32__) {
    return `Windows ${OS.release()}`
  } else {
    return `${OS.type()} ${OS.release()}`
  }
}
開發者ID:Ahskys,項目名稱:desktop,代碼行數:14,代碼來源:get-os.ts

示例3: browserCapabilities

export function browserCapabilities(userAgent: string): Set<BrowserCapability> {
  const ua = new UAParser(userAgent);
  const capabilities = new Set<BrowserCapability>();
  let browserName = ua.getBrowser().name || '';
  if (browserName === 'Chrome' && ua.getOS().name === 'iOS') {
    // Chrome on iOS is really Safari.
    browserName = 'Mobile Safari';
  }
  const predicates = browserPredicates[browserName] || {};
  for (const capability of Object.keys(predicates) as BrowserCapability[]) {
    if (predicates[capability](ua)) {
      capabilities.add(capability);
    }
  }
  return capabilities;
}
開發者ID:Polymer,項目名稱:tools,代碼行數:16,代碼來源:browser-capabilities.ts

示例4: test_parser

function test_parser() {
    var ua = 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6';
    var parser = new UAParser(ua);
    var result = parser.getResult();

    parser.getUA()
    parser.setUA("foo")

    result.ua

    // browser
    result.browser.name
    result.browser.version
    parser.getBrowser().name
    parser.getBrowser().version

    // device
    result.device.model
    result.device.type
    result.device.vendor

    parser.getDevice().model
    parser.getDevice().type
    parser.getDevice().vendor

    // Engine
    result.engine.name
    result.engine.version
    parser.getEngine().name
    parser.getEngine().version

    // OS
    result.os.name
    result.os.version
    parser.getOS().name
    parser.getOS().version

    // CPU
    result.cpu.architecture
    parser.getCPU().architecture

    // Extensions
    var uaString = 'ownbrowser/1.3';
    var ownBrowser = [[/(ownbrowser)\/([\w\.]+)/i], [UAParser.BROWSER.NAME, UAParser.BROWSER.VERSION]];
    var parser = new UAParser(uaString, { browser: ownBrowser });

}
開發者ID:TeamworkGuy2,項目名稱:DefinitelyTyped,代碼行數:47,代碼來源:ua-parser-js-tests.ts


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