src/middlewares/validate.js
function validateProperty(property, validator) {
    let isValid;
    if (!validator) {
        return void 0;
    }
    if (!property) {
        return void 0;
    }
    const {value} = property;
    const {options} = validator;
    const isValueNullOrUndefined = isNull(value) || isUndefined(value );
    isValid = (() => {
        switch (validator.type) {
            case 'required':
                const prevalidString = '' === property.value ? false : true;
                const prevalidDate = true;
                return true === validator.value ? (!isNull(value) && !isUndefined(value) && prevalidString && prevalidDate) : true;
            case 'regex':
                if (isValueNullOrUndefined) {
                    return true;
                }
                return validator.value.test(value);
            case 'email':
                if (isValueNullOrUndefined) {
                    return true;
                }
                return emailValidation(value, options);
            case 'number':
                return numberValidation(value, options);
            case 'string':
                const stringToValidate = value || '';
                return stringLength(stringToValidate, options);
            case 'date':
                return dateValidation(value, options);
            case 'function':
                return validator.value(value, options);
            case 'checkbox':
                return (isUndefined(value) || isNull(value)) ? false : true;
            default:
                return void 0;
        }
    })();
    if (isUndefined(isValid) || isNull(isValid)) {
        console.warn(`The validator of type: ${validator.type} is not defined`);
    } else if (false === isValid) {
        //Add the name of the property.
        return getErrorLabel(validator.type, property.modelName + '.' + property.name, options); //"The property " + property.name + " is invalid.";
    }
}
function validateProperty(property, validator) {
    let isValid;
    if (!validator) {
        return void 0;
    }
    if (!property) {
        return void 0;
    }
    const {value} = property;
    const {options} = validator;
    const isValueNullOrUndefined = isNull(value) || isUndefined(value );
    isValid = (() => {
        switch (validator.type) {
            case 'required':
                const prevalidString = '' === property.value ? false : true;
                const prevalidDate = true;
                return true === validator.value ? (!isNull(value) && !isUndefined(value) && prevalidString && prevalidDate) : true;
            case 'regex':
                if (isValueNullOrUndefined) {
                    return true;
                }
                return validator.value.test(value);
            case 'email':
                if (isValueNullOrUndefined) {
                    return true;
                }
                return emailValidation(value, options);
            case 'number':
                return numberValidation(value, options);
            case 'string':
                const stringToValidate = value || '';
                return stringLength(stringToValidate, options);
            case 'date':
                return dateValidation(value, options);
            case 'function':
                return validator.value(value, options);
            case 'checkbox':
                return (isUndefined(value) || isNull(value)) ? false : true;
            default:
                return void 0;
        }
    })();
    if (isUndefined(isValid) || isNull(isValid)) {
        console.warn(`The validator of type: ${validator.type} is not defined`);
    } else if (false === isValid) {
        //Add the name of the property.
        return getErrorLabel(validator.type, property.modelName + '.' + property.name, options); //"The property " + property.name + " is invalid.";
    }
}
function validateProperty ( property , validator ) { let isValid ; if ( ! validator ) { return void 0 ; } if ( ! property ) { return void 0 ; } const { value } = property ; const { options } = validator ; const isValueNullOrUndefined = isNull ( value ) || isUndefined ( value ) ; isValid = ( ( ) => { switch ( validator . type ) { case 'required' : const prevalidString = '' === property . value ? false : true ; const prevalidDate = true ; return true === validator . value ? ( ! isNull ( value ) && ! isUndefined ( value ) && prevalidString && prevalidDate ) : true ; case 'regex' : if ( isValueNullOrUndefined ) { return true ; } return validator . value . test ( value ) ; case 'email' : if ( isValueNullOrUndefined ) { return true ; } return emailValidation ( value , options ) ; case 'number' : return numberValidation ( value , options ) ; case 'string' : const stringToValidate = value || '' ; return stringLength ( stringToValidate , options ) ; case 'date' : return dateValidation ( value , options ) ; case 'function' : return validator . value ( value , options ) ; case 'checkbox' : return ( isUndefined ( value ) || isNull ( value ) ) ? false : true ; default : return void 0 ; } } ) ( ) ; if ( isUndefined ( isValid ) || isNull ( isValid ) ) { console . warn ( ` ${ validator . type } ` ) ; } else if ( false === isValid ) { //Add the name of the property. return getErrorLabel ( validator . type , property . modelName + '.' + property . name , options ) ; //"The property " + property.name + " is invalid."; } }
Validate a property.
@param  {object} property  - The property to validate.
@param  {function} validator - The validator to apply.
@return {object} - The property validation status.
Validate a property .