All files / src/validation/general index.js

87.5% Statements 7/8
83.33% Branches 5/6
100% Functions 1/1
87.5% Lines 7/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                      2x 2x 4x 4x 4x 1x             1x    
import global from '../../global';
 
/**
 * @function general
 * @description Test if a given string match at least one of the given regular expressions
 *
 * @param {String} string String to test
 * @param {Object} regexpObject Object with regular expression to test
 * @returns Boolean
 */
export default (string, regexpObject) => {
    Eif (string && regexpObject) {
        for (const key in regexpObject) { // eslint-disable-line
            try {
                const regexp = new RegExp(regexpObject[key]);
                if (regexp.test(string)) {
                    return key;
                }
            } catch (error) {
                global.logger.log(error.message);
            }
        }
    }
    return false;
};