Module: validator

Methods

(static) validateAge(person) → {void}

Validate the age of a person. Business rules: - The person object must exist - The person must contain a birth property - The user must be at least 18 years old
Parameters:
Name Type Description
person Object Object representing a person
Properties
Name Type Description
birth Date Birth date of the person
Source:
Throws:
  • INVALID_USER if person is missing or invalid
    Type
    Error
  • AGE_UNDER_18 if age is less than 18
    Type
    Error
Returns:
Type
void

(static) validateEmail(email) → {void}

Validate an email address. Business rules: - Must exist - Must be a string - Must follow a simple email pattern
Parameters:
Name Type Description
email string Email address to validate
Source:
Throws:
INVALID_EMAIL if: - value is missing - value is not a string - value does not match email format
Type
Error
Returns:
Type
void

(static) validateIdentity(value) → {void}

Validate identity (firstname or lastname). Business rules: - Must exist - Must be a string - Only letters (including accents) and hyphen allowed
Parameters:
Name Type Description
value string Firstname or lastname
Source:
Throws:
INVALID_IDENTITY if: - value is missing - value is not a string - value contains invalid characters
Type
Error
Returns:
Type
void

(static) validatePostalCode(code) → {void}

Validate a French postal code. Business rules: - Must exist - Must be a string - Must contain exactly 5 digits
Parameters:
Name Type Description
code string French postal code
Source:
Throws:
INVALID_POSTAL_CODE if: - value is missing - value is not a string - value does not match 5 digit format
Type
Error
Returns:
Type
void

(static) validateUser(user) → {boolean}

Validate a complete user object. This function delegates validation to: - validateAge - validatePostalCode - validateEmail - validateIdentity (firstname and lastname)
Parameters:
Name Type Description
user Object User object to validate
Properties
Name Type Description
birth Date Birth date
postalCode string Postal code
email string Email address
firstname string First name
lastname string Last name
Source:
Throws:
  • INVALID_USER if user object is invalid
    Type
    Error
  • Any error thrown by validation sub-functions
    Type
    Error
Returns:
Returns true if all validations pass
Type
boolean