1.2.0 • Published 1 year ago

@hakcolt/validator v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Validator

The validator is a dynamic tool and with it you will be able to validate any type of object and/or parameters that your use case requires as input, in addition to also being able to validate email, passwords and so on.

How To Use

/*...*/
  const missingAttributes = validation.validateObject(this, ["firstName:string", "lastName:string", "email:string", "gender:string", "password:string"])

  if (missingAttributes.length) {
    result.setError(resources.getWithParams(plurals.MISSING_ATRIBUTES, validation.formatMissingAttributes(missingAttributes)), 400)
    return false
    }

  if (!validation.validatePassword(this.password)) {
    result.setError(resources.get(strings.INVALID_PASSWORD), 400)
    return false
  }

  const genders = Object.values(Gender)
  if (!genders.includes(this.gender as Gender)) {
    result.setError(resources.get(strings.INVALID_GENDER), 400)
    return false
  }

  if (!validation.validateEmail(this.email)) {
    result.setError(resources.get(strings.INVALID_EMAIL), 400)
    return false
  }

  return true
/*...*/
1.2.0

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago