code: function validate (schema, data, key) {
    let value = data[key]
    const bool = value == null || value === ''
    const { required, type, validate, transform, elements } = schema
    const def = schema['default']
    // trigger error if undefined but required
    if (required && bool) throw new Error(`field ${key} is missing`)
    // coerce to type
    if (type && !bool) {
      let before = coerce(type, key, value)
      data[key] = elements
        ? (type === 'object' ? validator(before, elements) : before.map(item => validator(item, elements)))
        : before
    }
    // validate value
    if (validate) {
      const cb = check(validate, key)
      if (type === 'array') value.map(cb)
      else cb(value)
    }
    // apply default value
    if (def && bool) data[key] = def
    // apply transform
    if (transform && def == null) {
      data[key] = typeof transform === 'function'
        ? (type === 'array' ? value.map(transform) : transform(value))
        : transform
    }
  }
docs: Validate data key/value against passed schema.
  
  Required field is always check first in order to
  avoid unnecessary validations.
  
  @param {Object} schema
  @param {Object} data
  @param {String} key
  @api private