{"size": 1291, "ext": "js", "max_stars_repo_path": "src/validations.js", "max_stars_repo_name": "gak-github/form-validation", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/validations.js", "max_issues_repo_name": "gak-github/form-validation", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/validations.js", "max_forks_repo_name": "gak-github/form-validation", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.1025641026, "max_line_length": 148, "alphanum_fraction": 0.3648334624}
const emailRegEx = RegExp(/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i);
const validate = (fields) => {
    const error = {};
    Object.keys(fields).forEach( name => {
        const value = fields[name];
        switch (name) {
            case 'firstName':
                if (value.length < 5) {
                    error[name] = 'First Name must be 5 char long!';
                }
                break;
            case 'lastName':
                if (value.length < 5) {
                    error[name] = 'Last Name must be 5 char long!';
                }
                break;
            case 'email':
                if (!emailRegEx.test(value)) {
                    error[name] = 'Email is not valid';
                }
                break;
            case 'password':
                if (value.length < 4) {
                    error[name] = 'Password must be min 4 char long!';
                }
                break;
            case 'userAgreement':
                if (!value) {
                    error[name] = 'Agreement must be accepted';
                }
                break;
            default:
                break;
        }
    });
    return error;
};

export default validate;