function parseData(data, successCallback, failCallback) {
  let lines = data.split(lineDelim);

  // Expect at least, one header and one record.
  if (lines.length >= 2) {

    // Get header items. Those will be our field names.
    const fieldNames = lines.shift().split(delim);
    const numFields = fieldNames.length;
    const propertyNames = fieldNames.map((fieldName) => {
      const propertyName = fieldName.replace(/\s+/g, "");
      return propertyName.charAt(0).toLowerCase() + propertyName.slice(1);
    });

    if (numFields > 0) {
      const parsedData = lines.map((line) => {
        return line.split(delim).reduce((record, currentItem, index) => {
          const number = Number.parseFloat(currentItem);
          record[propertyNames[index]] = number ? number : currentItem;
          return record;
        }, {});
      });

      if (returnHtmlTable) {
        successCallback(parsedData, parseDataToHtmlTable(parsedData, fieldNames));
      } else {
        successCallback(parsedData);
      }
      return;
    }
  }

  failCallback("Unexpected format");
}
/**
 * Parse delimited data from string.
 * @private
 * @param  {string} data          {Input data read from url.}
 * @param  {function} successCallback {Callback in case of success.}
 * @param  {function} failCallback    {Callback in case of fail.}
 * @return {void}
 */
Parse delimited data from string.
Parse delimited data from string .
function parseData(data, successCallback, failCallback) {
  let lines = data.split(lineDelim);
  if (lines.length >= 2) {
    const fieldNames = lines.shift().split(delim);
    const numFields = fieldNames.length;
    const propertyNames = fieldNames.map((fieldName) => {
      const propertyName = fieldName.replace(/\s+/g, "");
      return propertyName.charAt(0).toLowerCase() + propertyName.slice(1);
    });
    if (numFields > 0) {
      const parsedData = lines.map((line) => {
        return line.split(delim).reduce((record, currentItem, index) => {
          const number = Number.parseFloat(currentItem);
          record[propertyNames[index]] = number ? number : currentItem;
          return record;
        }, {});
      });
      if (returnHtmlTable) {
        successCallback(parsedData, parseDataToHtmlTable(parsedData, fieldNames));
      } else {
        successCallback(parsedData);
      }
      return;
    }
  }
  failCallback("Unexpected format");
}
function parseData ( data , successCallback , failCallback ) { let lines = data . split ( lineDelim ) ; if ( lines . length >= 2 ) { const fieldNames = lines . shift ( ) . split ( delim ) ; const numFields = fieldNames . length ; const propertyNames = fieldNames . map ( ( fieldName ) => { const propertyName = fieldName . replace ( / \s+ / g , "" ) ; return propertyName . charAt ( 0 ) . toLowerCase ( ) + propertyName . slice ( 1 ) ; } ) ; if ( numFields > 0 ) { const parsedData = lines . map ( ( line ) => { return line . split ( delim ) . reduce ( ( record , currentItem , index ) => { const number = Number . parseFloat ( currentItem ) ; record [ propertyNames [ index ] ] = number ? number : currentItem ; return record ; } , { } ) ; } ) ; if ( returnHtmlTable ) { successCallback ( parsedData , parseDataToHtmlTable ( parsedData , fieldNames ) ) ; } else { successCallback ( parsedData ) ; } return ; } } failCallback ( "Unexpected format" ) ; }
Parse delimited data from string.
Parse delimited data from string .
// Expect at least, one header and one record. // Get header items. Those will be our field names.