Innovenergy_trunk/frontend/node_modules/testcafe/lib/utils/parse-user-agent.js

66 lines
9.0 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseUserAgent = exports.extractMetaInfo = exports.calculatePrettyUserAgent = void 0;
const bowser_1 = __importDefault(require("bowser"));
const DEFAULT_NAME = 'Other';
const DEFAULT_VERSION = '0.0';
const DEFAULT_PLATFORM_TYPE = DEFAULT_NAME.toLowerCase();
const EMPTY_PARSED_USER_AGENT = bowser_1.default.parse(' ');
const META_INFO_REGEX = /\([^(|^)]*\)/;
function calculateBrowser(browserDetails) {
return {
name: browserDetails.name || DEFAULT_NAME,
version: browserDetails.version || DEFAULT_VERSION,
};
}
function calculateOs(parsedOsDetails) {
const name = parsedOsDetails.name || DEFAULT_NAME;
let version = DEFAULT_VERSION;
// NOTE: a 'versionName' property value is more readable in the case of Windows (GH-481):
// Windows 8.1: os.version: "NT 6.3", os.versionName: "8.1".
if (name.toLowerCase() === 'windows') {
if (parsedOsDetails.versionName)
version = parsedOsDetails.versionName;
}
else if (parsedOsDetails.version)
version = parsedOsDetails.version;
return { name, version };
}
function calculateEngine(engineDetails) {
return {
name: engineDetails.name || DEFAULT_NAME,
version: engineDetails.version || DEFAULT_VERSION,
};
}
function calculatePrettyUserAgent(browser, os) {
return `${browser.name} ${browser.version} / ${os.name} ${os.version}`;
}
exports.calculatePrettyUserAgent = calculatePrettyUserAgent;
function extractMetaInfo(prettyUserAgent) {
const parenthesisExpressions = prettyUserAgent.match(META_INFO_REGEX);
if (!parenthesisExpressions || !parenthesisExpressions.length)
return '';
return parenthesisExpressions[parenthesisExpressions.length - 1].replace(/[()]/g, '');
}
exports.extractMetaInfo = extractMetaInfo;
function parseUserAgent(userAgent = '') {
const parsedUserAgent = userAgent ? bowser_1.default.parse(userAgent) : EMPTY_PARSED_USER_AGENT;
const browser = calculateBrowser(parsedUserAgent.browser);
const os = calculateOs(parsedUserAgent.os);
const engine = calculateEngine(parsedUserAgent.engine);
const prettyUserAgent = calculatePrettyUserAgent(browser, os);
return {
name: browser.name,
version: browser.version,
platform: parsedUserAgent.platform.type || DEFAULT_PLATFORM_TYPE,
os,
engine,
prettyUserAgent: prettyUserAgent,
userAgent,
};
}
exports.parseUserAgent = parseUserAgent;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGFyc2UtdXNlci1hZ2VudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9wYXJzZS11c2VyLWFnZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLG9EQUE0QjtBQUU1QixNQUFNLFlBQVksR0FBYyxPQUFPLENBQUM7QUFDeEMsTUFBTSxlQUFlLEdBQVcsS0FBSyxDQUFDO0FBQ3RDLE1BQU0scUJBQXFCLEdBQUssWUFBWSxDQUFDLFdBQVcsRUFBRSxDQUFDO0FBQzNELE1BQU0sdUJBQXVCLEdBQUcsZ0JBQU0sQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUM7QUFDbEQsTUFBTSxlQUFlLEdBQUcsY0FBYyxDQUFDO0FBaUJ2QyxTQUFTLGdCQUFnQixDQUFFLGNBQTRDO0lBQ25FLE9BQU87UUFDSCxJQUFJLEVBQUssY0FBYyxDQUFDLElBQUksSUFBSSxZQUFZO1FBQzVDLE9BQU8sRUFBRSxjQUFjLENBQUMsT0FBTyxJQUFJLGVBQWU7S0FDckQsQ0FBQztBQUNOLENBQUM7QUFFRCxTQUFTLFdBQVcsQ0FBRSxlQUF3QztJQUMxRCxNQUFNLElBQUksR0FBRyxlQUFlLENBQUMsSUFBSSxJQUFJLFlBQVksQ0FBQztJQUVsRCxJQUFJLE9BQU8sR0FBRyxlQUFlLENBQUM7SUFFOUIseUZBQXlGO0lBQ3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