src/core/validator.js
function validate (validations, bail, data, fields, messages, formatter) {
  return new Promise((resolve, reject) => {
    messages = messages || {}

    /**
     * This is expanded form of fields and rules
     * applied on them
     */
    const parsedFields = parse(fields, data)

    /**
     * A flat validations stack, each node is a lazy promise
     */
    const validationsStack = getValidationsStack(validations, parsedFields, data, messages, formatter)

    pSeries(validationsStack, bail)
      .then((response) => {
        const errors = formatter.toJSON()
        if (errors) {
          return reject(errors)
        }
        resolve(data)
      })
  })
}
function validate (validations, bail, data, fields, messages, formatter) {
  return new Promise((resolve, reject) => {
    messages = messages || {}

    /**
     * This is expanded form of fields and rules
     * applied on them
     */
    const parsedFields = parse(fields, data)

    /**
     * A flat validations stack, each node is a lazy promise
     */
    const validationsStack = getValidationsStack(validations, parsedFields, data, messages, formatter)

    pSeries(validationsStack, bail)
      .then((response) => {
        const errors = formatter.toJSON()
        if (errors) {
          return reject(errors)
        }
        resolve(data)
      })
  })
}
function validate ( validations , bail , data , fields , messages , formatter ) { return new Promise ( ( resolve , reject ) => { messages = messages || { } /**
     * This is expanded form of fields and rules
     * applied on them
     */ const parsedFields = parse ( fields , data ) /**
     * A flat validations stack, each node is a lazy promise
     */ const validationsStack = getValidationsStack ( validations , parsedFields , data , messages , formatter ) pSeries ( validationsStack , bail ) . then ( ( response ) => { const errors = formatter . toJSON ( ) if ( errors ) { return reject ( errors ) } resolve ( data ) } ) } ) }
Run `validations` on `data` using rules defined on `fields`.

@method validate

@param {Object}  validations  - Object of available validations
@param {Boolean} bail         - Whether to bail on first error or not
@param {Object}  data         - Data to validate
@param {Object}  fields       - Fields and their rules
@param {Object}  messages     - Custom messages
@param {Object}  formatter    - Formatter to be used

@returns {Promise} Promise is rejected with an array of errors or resolved with original data
Run validations on data using rules defined on fields .