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