lib/utils.js
function parser (defaults, validators, mappers) {
  return function (opts) {
    const merged = mergeObjects(defaults, opts)

    Object.keys(merged).forEach((key) => {
      if (validators[key] && ! validators[key](merged[key]))
        throw new Error('Failed to validate ' + key)

      if (mappers && mappers[key])
        merged[key] = mappers[key](merged[key])
    })

    return merged
  }
}
function parser (defaults, validators, mappers) {
  return function (opts) {
    const merged = mergeObjects(defaults, opts)

    Object.keys(merged).forEach((key) => {
      if (validators[key] && ! validators[key](merged[key]))
        throw new Error('Failed to validate ' + key)

      if (mappers && mappers[key])
        merged[key] = mappers[key](merged[key])
    })

    return merged
  }
}
function parser ( defaults , validators , mappers ) { return function ( opts ) { const merged = mergeObjects ( defaults , opts ) Object . keys ( merged ) . forEach ( ( key ) => { if ( validators [ key ] && ! validators [ key ] ( merged [ key ] ) ) throw new Error ( 'Failed to validate ' + key ) if ( mappers && mappers [ key ] ) merged [ key ] = mappers [ key ] ( merged [ key ] ) } ) return merged } }
Creates function to validate and transform objects.
Useful for parsing of options objects
@returns {object} Parsed, validated and transformed object
@param {object} defaults - of default values used if absent from object being parsed
@param {object} validators - of methods used to validate values of object being parsed
@param {object} mappers - of methods used to transform values after successful validation
Creates function to validate and transform objects . Useful for parsing of options objects