All files / src/validation/isValid index.js

85.71% Statements 6/7
100% Branches 6/6
100% Functions 1/1
85.71% Lines 6/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                      37x 34x 34x 34x 22x           15x    
import global from '../../global';
 
/**
 * @function isValid
 * @description Test if a given string match the given regular expression
 *
 * @param {String} string String to test
 * @param {String} regexpValue regular expression to test
 * @returns Boolean
 */
export default (string, regexpValue) => {
    if (string && regexpValue) {
        try {
            const regexp = new RegExp(regexpValue);
            if (regexp.test(string)) {
                return true;
            }
        } catch (error) {
            global.logger.warn(error.message);
        }
    }
    return false;
};