|
|
|
class Utils {
|
|
|
|
/**
|
|
|
|
* Get first matched item for a string
|
|
|
|
* @param {RegExp} regexp
|
|
|
|
* @param {String} ua
|
|
|
|
* @return {Array|{index: number, input: string}|*|boolean|string}
|
|
|
|
*/
|
|
|
|
static getFirstMatch(regexp, ua) {
|
|
|
|
const match = ua.match(regexp);
|
|
|
|
return (match && match.length > 0 && match[1]) || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get second matched item for a string
|
|
|
|
* @param regexp
|
|
|
|
* @param {String} ua
|
|
|
|
* @return {Array|{index: number, input: string}|*|boolean|string}
|
|
|
|
*/
|
|
|
|
static getSecondMatch(regexp, ua) {
|
|
|
|
const match = ua.match(regexp);
|
|
|
|
return (match && match.length > 1 && match[2]) || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Match a regexp and return a constant or undefined
|
|
|
|
* @param {RegExp} regexp
|
|
|
|
* @param {String} ua
|
|
|
|
* @param {*} _const Any const that will be returned if regexp matches the string
|
|
|
|
* @return {*}
|
|
|
|
*/
|
|
|
|
static matchAndReturnConst(regexp, ua, _const) {
|
|
|
|
if (regexp.test(ua)) {
|
|
|
|
return _const;
|
|
|
|
}
|
|
|
|
return void (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getWindowsVersionName(version) {
|
|
|
|
switch (version) {
|
|
|
|
case 'NT': return 'NT';
|
|
|
|
case 'XP': return 'XP';
|
|
|
|
case 'NT 5.0': return '2000';
|
|
|
|
case 'NT 5.1': return 'XP';
|
|
|
|
case 'NT 5.2': return '2003';
|
|
|
|
case 'NT 6.0': return 'Vista';
|
|
|
|
case 'NT 6.1': return '7';
|
|
|
|
case 'NT 6.2': return '8';
|
|
|
|
case 'NT 6.3': return '8.1';
|
|
|
|
case 'NT 10.0': return '10';
|
|
|
|
default: return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Utils;
|