index.js
function coerce (type, field, value) {
  let result
  if (type === 'string') {
    result = String(value).trim()
  } else if (type === 'number') {
    result = Number(value)
    if (isNaN(result)) throw new Error(`field ${field} can not be converted to a number`)
  } else if (type === 'array') {
    result = [].concat(value)
  } else if (type === 'date') {
    result = Date.parse(value)
    if (isNaN(result)) throw new Error(`field ${field} can not be converted into a date`)
  } else if (type === 'boolean') {
    result = Boolean(value)
  } else if (type === 'object') {
    if (typeof value !== 'object') throw new Error(`field ${field} is not an object`)
    result = value
  }
  return result
}
function coerce (type, field, value) {
  let result
  if (type === 'string') {
    result = String(value).trim()
  } else if (type === 'number') {
    result = Number(value)
    if (isNaN(result)) throw new Error(`field ${field} can not be converted to a number`)
  } else if (type === 'array') {
    result = [].concat(value)
  } else if (type === 'date') {
    result = Date.parse(value)
    if (isNaN(result)) throw new Error(`field ${field} can not be converted into a date`)
  } else if (type === 'boolean') {
    result = Boolean(value)
  } else if (type === 'object') {
    if (typeof value !== 'object') throw new Error(`field ${field} is not an object`)
    result = value
  }
  return result
}
function coerce ( type , field , value ) { let result if ( type === 'string' ) { result = String ( value ) . trim ( ) } else if ( type === 'number' ) { result = Number ( value ) if ( isNaN ( result ) ) throw new Error ( ` ${ field } ` ) } else if ( type === 'array' ) { result = [ ] . concat ( value ) } else if ( type === 'date' ) { result = Date . parse ( value ) if ( isNaN ( result ) ) throw new Error ( ` ${ field } ` ) } else if ( type === 'boolean' ) { result = Boolean ( value ) } else if ( type === 'object' ) { if ( typeof value !== 'object' ) throw new Error ( ` ${ field } ` ) result = value } return result }
Coerce value.

Trigger

@param {String} type
@param {String} field name
@param {Any} value
@api private
Coerce value .