app/js/invertedIndex.js
/**
   * Validate File
   * @function
   * @param {string} fileToValidate content of the file uploaded
   * @return {Object} returns either errorMsg or result.
   */
Validate File
@function
@param {string} fileToValidate content of the file uploaded
@return {Object} returns either errorMsg or result.
Validate File @function @param { string } fileToValidate content of the file uploaded @return { Object } returns either errorMsg or result .
static validateFile(fileToValidate) {
    let result = {};
    const errorMsg = {
      success: false,
      message: 'has an invalid JSON format.'
    };
    try {
      result = {
        success: true,
        message: 'File is valid',
        fileToValidate
      };
      fileToValidate.forEach((book) => {
        if (typeof book !== 'object' || Object.keys(book).length !== 2) {
          errorMsg.message = 'has not only one key';
          throw errorMsg;
        }
        if (book.title === undefined || book.text === undefined) {
          errorMsg.message = 'does not have title or text defined';
          throw errorMsg;
        }
        if (book.title === '' || book.text === '') {
          errorMsg.message = 'cannot be empty';
          throw errorMsg;
        }
      });
    } catch (error) {
      if (error.success === false) return errorMsg;
    }
    return result;
  }
static validateFile ( fileToValidate ) { let result = { } ; const errorMsg = { success : false , message : 'has an invalid JSON format.' } ; try { result = { success : true , message : 'File is valid' , fileToValidate } ; fileToValidate . forEach ( ( book ) => { if ( typeof book !== 'object' || Object . keys ( book ) . length !== 2 ) { errorMsg . message = 'has not only one key' ; throw errorMsg ; } if ( book . title === undefined || book . text === undefined ) { errorMsg . message = 'does not have title or text defined' ; throw errorMsg ; } if ( book . title === '' || book . text === '' ) { errorMsg . message = 'cannot be empty' ; throw errorMsg ; } } ) ; } catch ( error ) { if ( error . success === false ) return errorMsg ; } return result ; }
Validate File
 @function
 @param {string} fileToValidate content of the file uploaded
 @return {Object} returns either errorMsg or result.
Validate File @function @param { string } fileToValidate content of the file uploaded @return { Object } returns either errorMsg or result .