tasks/scrapeData.js
/*
  Check if the provided data contains any invalid fields
*/
Check if the provided data contains any invalid fields
Check if the provided data contains any invalid fields
function isValid(data) {
  if (data.cases === undefined) {
    throw new Error(`Invalid data: contains no case data`);
  }
  for (const [prop, value] of Object.entries(data)) {
    if (value === null) {
      throw new Error(`Invalid data: ${prop} is null`);
    }
    if (Number.isNaN(value)) {
      throw new Error(`Invalid data: ${prop} is not a number`);
    }
  }
  for (const prop of numericalValues) {
    if (data[prop] !== undefined && typeof data[prop] !== 'number') {
      throw new Error(`Invalid data: ${prop} is not a number`);
    }
  }
  return true;
}
function isValid ( data ) { if ( data . cases === undefined ) { throw new Error ( ` ` ) ; } for ( const [ prop , value ] of Object . entries ( data ) ) { if ( value === null ) { throw new Error ( ` ${ prop } ` ) ; } if ( Number . isNaN ( value ) ) { throw new Error ( ` ${ prop } ` ) ; } } for ( const prop of numericalValues ) { if ( data [ prop ] !== undefined && typeof data [ prop ] !== 'number' ) { throw new Error ( ` ${ prop } ` ) ; } } return true ; }
Check if the provided data contains any invalid fields
Check if the provided data contains any invalid fields