{"size": 800, "ext": "js", "max_stars_repo_path": "src/validators/profileValidator.js", "max_stars_repo_name": "OhtuHunt/HuntForGloryBackend", "max_stars_repo_stars_event_min_datetime": "2018-02-22T13:49:31.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-22T13:49:31.000Z", "max_issues_repo_path": "src/validators/profileValidator.js", "max_issues_repo_name": "OhtuHunt/HuntForGloryFrontend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/validators/profileValidator.js", "max_forks_repo_name": "OhtuHunt/HuntForGloryFrontend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.0, "max_line_length": 110, "alphanum_fraction": 0.655}
import validator from 'validator'

const validateProfile = (user) => {
    let errorArray = []

    errorArray = errorArray.concat(validateProfileName(user.username), validateEmail(user.email))

    let errors = []

    errorArray.forEach(error => {
        if (error) {
            errors = errors.concat(error)
        }
    })
    return errors
}

const validateProfileName = (username) => {
    if (validator.isLength(username, {min: 1, max: 15}) && validator.isAlphanumeric(username)) {
        return
    }
    return 'Username must only contain alphanumeric characters and has to be between 1 and 15 characters long'
}

const validateEmail = (email) => {
    if (validator.isEmail(email)) {
        return
    }
    return 'Email must be a valid email adress'
}

export default validateProfile