You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1004 B
40 lines
1004 B
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);
|
|
}
|
|
}
|
|
|
|
module.exports = Utils;
|