本文整理汇总了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;
}
示例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()}`
}
}
示例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;
}
示例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 });
}