當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript papaparse.parse函數代碼示例

本文整理匯總了TypeScript中papaparse.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了parse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: parseAndNormalize

	parseAndNormalize() {
		let csv;
		if (typeof document == "boolean") {	// "boolean" is for false
			let csvObj = Papa.parse(this.data, {
				header: true,
				dynamicTyping: true,
				skipEmptyLines: true,
				comments: "#",
			});
			csv = csvObj.data;
		} else {
			csv = Table.fromText(this.data);
			csv.logger = this.logger;
		}
		this.data = null;	// save RAM
		this.log('rows after parse', csv.length);
		csv = csv.trim();
		// csv = csv.trimAll(); // prevents analyzeCSV from working
		this.log('rows after trim', csv.length);
		csv = this.analyzeCSV(csv);
		this.log('rows after analyze', csv.length);
		csv = this.normalizeCSV(csv);
		this.log('rows after normalize', csv.length);
		csv = this.convertDataTypes(csv);
		this.log('rows after convertDataTypes', csv.length);
		return csv;
	}
開發者ID:spidgorny,項目名稱:umsaetze,代碼行數:27,代碼來源:ParseCSV.ts

示例2: error

      options.fileReader.readText(fullFilePath, (err, data) => {
        if (err) {
          error(`fail "${filePath}" reading`, err);
          return reject(new DdfCsvError(FILE_READING_ERROR, err, fullFilePath));
        }

        Papa.parse(stripBom(data), {
          header: true,
          skipEmptyLines: true,
          dynamicTyping: (headerName) => {
            // can't do dynamic typing without concept types loaded.
            // concept properties are not parsed in first concept query
            // reparsing of concepts resource is done in conceptLookup building
            if (!options.conceptsLookup) {
              return true;
            }

            // parsing to number/boolean based on concept type
            const concept: any = options.conceptsLookup.get(headerName) || {};

            return includes([ 'boolean', 'measure' ], concept.concept_type);
          },
          complete: result => {
            debug(`finish reading "${filePath}"`);
            resolve(result);
          },
          error: parseErr => {
            error(`fail "${filePath}" parsing`, parseErr);
            reject(new DdfCsvError(CSV_PARSING_ERROR, parseErr, filePath));
          }
        });
      });
開發者ID:VS-work,項目名稱:vizabi-ddfcsv-reader,代碼行數:32,代碼來源:ddf-csv.ts

示例3: fromCSV

export function fromCSV(data: string, nameColIndex?: number, tagsColIndex?: number): Record[] {
    const parsed = parse(data);
    if (parsed.errors.length) {
        throw new ImportError("invalid_csv");
    }
    return fromTable(parsed.data, nameColIndex, tagsColIndex);
}
開發者ID:MaKleSoft,項目名稱:padlock,代碼行數:7,代碼來源:import.ts

示例4: dumpToCSV

 public dumpToCSV(resultFile: string) {
   const newResult = _.mapKeys(this.result as _.Dictionary<any>, (v, k) => {
     if (k !== 'repoName') {
       return `${requestTypeMapping.get(this.requestType)}_${k}`;
     } else {
       return 'repoName';
     }
   });
   if (!fs.existsSync(resultFile)) {
     console.log(papa.unparse([newResult]));
     fs.writeFileSync(resultFile, papa.unparse([newResult]));
   } else {
     const file = fs.createReadStream(resultFile);
     papa.parse(file, {
       header: true,
       complete: parsedResult => {
         const originResults = parsedResult.data;
         const index = originResults.findIndex(originResult => {
           return originResult.repoName === newResult.repoName;
         });
         if (index === -1) {
           originResults.push(newResult);
         } else {
           originResults[index] = { ...originResults[index], ...newResult };
         }
         fs.writeFileSync(resultFile, papa.unparse(originResults));
       },
     });
   }
 }
開發者ID:elastic,項目名稱:kibana,代碼行數:30,代碼來源:lsp_test_runner.ts

示例5: trimAndRemoveQuotes

export const csvToMap = (csv: string): MapResult => {
  let errors = []
  const trimmed = _.trimEnd(csv, '\n')
  const parsedTVS = Papa.parse(trimmed)
  const templateValuesData: string[][] = _.get(parsedTVS, 'data', [[]])

  if (templateValuesData.length === 0) {
    return {values: {}, errors}
  }

  const keys = new Set<string>()
  let values = {}

  for (const arr of templateValuesData) {
    if (arr.length === 2 || (arr.length === 3 && arr[2] === '')) {
      const key = trimAndRemoveQuotes(arr[0])
      const value = trimAndRemoveQuotes(arr[1])

      if (!keys.has(key) && key !== '') {
        values[key] = value
        keys.add(key)
      }
    } else {
      errors = [...errors, arr[0]]
    }
  }

  return {values, errors}
}
開發者ID:influxdata,項目名稱:influxdb,代碼行數:29,代碼來源:mapBuilder.ts

示例6: readFile

 readFile(file: File): void {
     this._transactions = [];
     let result = Papa.parse(file, {
         delimiter: ";",
         header: true,
         skipEmptyLines: true,
         encoding: "utf-8",
         complete: (result) => {
             // it is a german localized file format:
             // Date format: dd.mm.yyyy
             // Number format: xxx,xx
             for (let row of result.data) {
                 var tvm = new TransactionViewModel();
                 let timeStamp = this.dataParser.parseTimeStamp(row["Wertstellung"], "DD.MM.YYYY");
                 tvm = this.assignTimeStamp(tvm, timeStamp, false);
                 tvm.note = row["Buchungstext"];
                 tvm.value = this.dataParser.parseNumber(row["Betrag"]);
                 tvm.personId = this.dbValueProvider.getPersonIdFromName(row["Buchungstext"]);
                 tvm.currencyAccountId = this.dbValueProvider.getCurrencyAccountIdFromName("Konto", "EUR");
                 this.addRawData(tvm, row, result.meta.fields);
                 this._transactions.push(tvm);
             }
         }
     });
 }
開發者ID:Koopakiller,項目名稱:MultiDimensional-MindManager,代碼行數:25,代碼來源:Importer.ts

示例7: fromLastPass

export function fromLastPass(data: string): Record[] {
    let records = parse(data).data
        // Remove first row as it only contains field names
        .slice(1)
        // Filter out empty rows
        .filter(row => row.length > 1)
        .map(lpParseRow);

    return records;
}
開發者ID:MaKleSoft,項目名稱:padlock,代碼行數:10,代碼來源:import.ts

示例8: async

  return new Promise<BindableMoneyTransaction[]>((resolve) => {
    const onComplete = async (results: ParseResult) => {
      const repository = await ImportFacade.importToDb(results.data);
      resolve(await repository.pullAll());
    };

    papaparse.parse(csv, {
      header  : true,
      complete: onComplete
    } as ParseConfig);
  });
開發者ID:armorik83,項目名稱:reveal-wealth,代碼行數:11,代碼來源:import-data.action.ts

示例9:

export const parseResponseError = (response: string): FluxTable[] => {
  const data = Papa.parse(response.trim()).data as string[][]

  return [
    {
      id: uuid.v4(),
      name: 'Error',
      result: '',
      groupKey: {},
      dataTypes: {},
      data,
    },
  ]
}
開發者ID:influxdata,項目名稱:influxdb,代碼行數:14,代碼來源:response.ts

示例10: parseString

  parseString(csvString: string): CoreColumnTable {
    let result: PapaParse.ParseResult = Papa.parse(csvString, this.options);

    let numRows: number = result.data.length;
    let fields: string[] = [];
    let attrVectors: any[][] = [];

    if (result.meta.fields) {
      fields = result.meta.fields;

      // Create attribute vectors
      for (let c: number = 0; c < fields.length; ++c) {
        let vector: any[] = [];
        for (let r: number = 0; r < numRows; ++r) {
          vector.push(result.data[r][fields[c]]);
        }
        attrVectors.push(vector);
      }
    } else {
      // Find the number of columns needed for all rows
      let numColumns: number = 0;
      for (let r: number = 0; r < numRows; ++r) {
        numColumns = Math.max(numColumns, result.data[r].length);
      }

      // Initialize fields
      for (let c: number = 0; c < numColumns; ++c) {
        fields.push('Column ' + (c + 1));
      }

      // Fill attribute vectors
      for (let c: number = 0; c < numColumns; ++c) {
        let vector: any[] = [];
        for (let r: number = 0; r < numRows; ++r) {
          vector.push(result.data[r][c]);
        }
        attrVectors.push(vector);
      }
    }

    // Create the table
    let table: CoreColumnTable = new CoreColumnTable({
      fields: fields,
      columns: attrVectors
    });
    table.detectTypes(true);

    return table;
  }
開發者ID:torpedro,項目名稱:datatable.js,代碼行數:49,代碼來源:CSVParser.ts

示例11: constructor

 constructor() {
     var self = this;
     Papa.parse('/data/food.csv', {
         download: true,
         header: true,
         skipEmptyLines: true,
         complete: function (results) {
             self.indices = results.data.map(item => {
                 return {
                     id: parseInt(item['ID']),
                     name: item['Name'],
                     index: parseInt(item['Glycemic Index'])
                 };
             });
         }
     });
 }
開發者ID:leejefon,項目名稱:healthiq-blood-sugar-simulator,代碼行數:17,代碼來源:FoodService.ts

示例12: return

 return (modelCsv: string) => {
   return Papa.parse(modelCsv).data as T[]
 }
開發者ID:likr,項目名稱:interactive-sem,代碼行數:3,代碼來源:papa-parse-provider.service.ts

示例13:

 const parsedChunks = chunks.map(c => Papa.parse(c).data)
開發者ID:influxdata,項目名稱:influxdb,代碼行數:1,代碼來源:rawFluxDataTable.ts

示例14: Error

export const parseTables = (responseChunk: string): FluxTable[] => {
  const lines = responseChunk.split('\n')
  const annotationLines: string = lines
    .filter(line => line.startsWith('#'))
    .join('\n')
    .trim()
  const nonAnnotationLines: string = lines
    .filter(line => !line.startsWith('#'))
    .join('\n')
    .trim()

  if (_.isEmpty(annotationLines)) {
    throw new Error('Unable to extract annotation data')
  }

  if (_.isEmpty(nonAnnotationLines)) {
    // A response may be truncated on an arbitrary line. This guards against
    // the case where a response is truncated on annotation data
    return []
  }

  const nonAnnotationData = Papa.parse(nonAnnotationLines).data
  const annotationData = Papa.parse(annotationLines).data
  const headerRow = nonAnnotationData[0]
  const tableColIndex = headerRow.findIndex(h => h === 'table')
  const resultColIndex = headerRow.findIndex(h => h === 'result')

  interface TableGroup {
    [tableId: string]: string[]
  }

  // Group rows by their table id
  const tablesData = Object.values(
    _.groupBy<TableGroup[]>(
      nonAnnotationData.slice(1),
      row => row[tableColIndex]
    )
  )

  const groupRow = annotationData.find(row => row[0] === '#group')
  const defaultsRow = annotationData.find(row => row[0] === '#default')
  const dataTypeRow = annotationData.find(row => row[0] === '#datatype')

  // groupRow = ['#group', 'false', 'true', 'true', 'false']
  const groupKeyIndices = groupRow.reduce((acc, value, i) => {
    if (value === 'true') {
      return [...acc, i]
    }

    return acc
  }, [])

  const tables = tablesData.map(tableData => {
    const dataRow = _.get(tableData, '0', defaultsRow)

    const result: string =
      _.get(dataRow, resultColIndex, '') ||
      _.get(defaultsRow, resultColIndex, '')

    const groupKey = groupKeyIndices.reduce((acc, i) => {
      return {...acc, [headerRow[i]]: _.get(dataRow, i, '')}
    }, {})

    const name = Object.entries(groupKey)
      .filter(([k]) => !['_start', '_stop'].includes(k))
      .map(([k, v]) => `${k}=${v}`)
      .join(' ')

    const dataTypes = dataTypeRow.reduce(
      (acc, dataType, i) => ({
        ...acc,
        [headerRow[i]]: dataType,
      }),
      {}
    )

    return {
      id: uuid.v4(),
      data: [[...headerRow], ...tableData],
      name,
      result,
      groupKey,
      dataTypes,
    }
  })

  return tables
}
開發者ID:influxdata,項目名稱:influxdb,代碼行數:88,代碼來源:response.ts

示例15: isCSV

export function isCSV(data: string): Boolean {
    return parse(data).errors.length === 0;
}
開發者ID:MaKleSoft,項目名稱:padlock,代碼行數:3,代碼來源:import.ts


注:本文中的papaparse.parse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。