Code coverage report for src/Common/Assert/Regex.js

Statements: 100% (8 / 8)      Branches: 100% (2 / 2)      Functions: 100% (1 / 1)      Lines: 100% (8 / 8)      Ignored: none     

All files » src/Common/Assert/ » Regex.js
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 27 28 29 30 31 32 33    1                               1   7   7   7 4     3       1
'use strict';
 
var _           = require("lodash"),
    Type        = require("../Type"),
    Safe        = require("../Safe"),
    Exception   = require("../Exception/Exception");
 
/**
 *
 * Test the regex
 *
 * @throws {Exception}
 *
 * @param {*}               val
 * @param {String|Regex}    regex
 * @return {*}
 *
 */
var Regex = function(val, regex){
 
    regex = Safe.regexp(regex);
 
    var isValid = !!regex.exec(val);
 
    if(!isValid){
        throw new Exception("REGEXP", { value: val });
    }
 
    return val;
 
};
 
module.exports = Regex;