1
0
mirror of https://github.com/lancedikson/bowser synced 2024-09-28 22:30:44 +00:00
lancedikson_bowser/src/utils.js

40 lines
1003 B
JavaScript
Raw Normal View History

2017-04-04 20:03:47 +00:00
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
2017-04-09 14:13:00 +00:00
* @param {String} ua
2017-04-04 20:03:47 +00:00
* @return {Array|{index: number, input: string}|*|boolean|string}
*/
static getSecondMatch(regexp, ua) {
const match = ua.match(regexp);
return (match && match.length > 1 && match[2]) || '';
}
2017-05-18 20:56:26 +00:00
/**
* 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);
}
2017-04-04 20:03:47 +00:00
}
module.exports = Utils;