function checkRequired(obj, required = [], conditionallyIgnored = []) {
  // Make a copy since we modify it below
  required = required.slice();

  const errors = [];
  for (let key in obj) {
    if (required.includes(key)) {
      if (!obj[key])
        errors.push(new Error(`Parameter must not be empty: ${key}`));
      required.splice(required.indexOf(key), 1);
    }
    if (conditionallyIgnored.includes(key) && Boolean(obj[key]))
      errors.push(new Error(`Parameter must be skipped, be empty, or evaluate to false: ${key}`));

  }
  if (required.length)
    errors.push(new Error(`Missing the following parameter(s): ${required.join(', ')}`));

  return errors;
}
/**
 * Check if we have "truthy" values for all required fields in a given object
 * (typically an API request body). Also throws errors if given fields are
 * present with a "truthy" value, which is useful for conflicting parameters
 * that may be submitted with empty values.
 *
 * @param {Object} obj
 *  any object whose keys we want to validate
 * @param {String[]} [required=[]]
 *  keys which must access a truthy value
 * @param {String[]} [conditionallyIgnored=[]]
 *  keys which will be ignored _unless_ they access a truthy value
 * @returns {Error[]}
 *  errors for each validation issue or an empty array
 * @memberof APIUploadHandler
 */
Check if we have "truthy" values for all required fields in a given object
(typically an API request body). Also throws errors if given fields are
present with a "truthy" value, which is useful for conflicting parameters
that may be submitted with empty values.


Check if we have " truthy " values for all required fields in a given object ( typically an API request body ) . Also throws errors if given fields are present with a " truthy " value which is useful for conflicting parameters that may be submitted with empty values .
function checkRequired(obj, required = [], conditionallyIgnored = []) {
  required = required.slice();
  const errors = [];
  for (let key in obj) {
    if (required.includes(key)) {
      if (!obj[key])
        errors.push(new Error(`Parameter must not be empty: ${key}`));
      required.splice(required.indexOf(key), 1);
    }
    if (conditionallyIgnored.includes(key) && Boolean(obj[key]))
      errors.push(new Error(`Parameter must be skipped, be empty, or evaluate to false: ${key}`));
  }
  if (required.length)
    errors.push(new Error(`Missing the following parameter(s): ${required.join(', ')}`));
  return errors;
}
function checkRequired ( obj , required = [ ] , conditionallyIgnored = [ ] ) { required = required . slice ( ) ; const errors = [ ] ; for ( let key in obj ) { if ( required . includes ( key ) ) { if ( ! obj [ key ] ) errors . push ( new Error ( ` ${ key } ` ) ) ; required . splice ( required . indexOf ( key ) , 1 ) ; } if ( conditionallyIgnored . includes ( key ) && Boolean ( obj [ key ] ) ) errors . push ( new Error ( ` ${ key } ` ) ) ; } if ( required . length ) errors . push ( new Error ( ` ${ required . join ( ', ' ) } ` ) ) ; return errors ; }
Check if we have "truthy" values for all required fields in a given object
 (typically an API request body).
Check if we have " truthy " values for all required fields in a given object ( typically an API request body ) .
// Make a copy since we modify it below