本文整理汇总了TypeScript中papaparse.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16:
const results = await new Promise<Papa.ParseResult>((resolve, reject) =>
Papa.parse(file, {
header: true,
complete: resolve,
error: reject
})
开发者ID:w1cked,项目名称:DIM,代码行数:6,代码来源:dimCsvService.factory.ts
示例17: csv
export function csv(): NullContextFunction<'csv', Arguments, Datatable> {
const { help, args: argHelp } = getFunctionHelp().csv;
return {
name: 'csv',
type: 'datatable',
help,
context: {
types: ['null'],
},
args: {
data: {
aliases: ['_'],
types: ['string'],
help: argHelp.data,
},
delimiter: {
types: ['string'],
help: argHelp.delimiter,
},
newline: {
types: ['string'],
help: argHelp.newline,
},
},
fn(_context, args) {
const { data: csvString, delimiter, newline } = args;
const config: Papa.ParseConfig = {
transform: (val: string) => {
if (val.indexOf('"') >= 0) {
return val.trim().replace(/(^\"|\"$)/g, '');
}
return val;
},
};
if (delimiter != null) {
config.delimiter = delimiter;
}
if (newline != null) {
config.newline = newline;
}
const output = Papa.parse(csvString, config);
const { data, errors } = output;
if (errors.length > 0) {
throw new Error('Error parsing input CSV.');
}
// output.data is an array of arrays, rows and values in each row
return data.reduce(
(acc, row, i) => {
if (i === 0) {
// first row, assume header values
row.forEach((colName: string) =>
acc.columns.push({ name: colName.trim(), type: 'string' })
);
} else {
// any other row is a data row
const rowObj = row.reduce((rowAcc: string[], colValue: string, j: number) => {
const colName = acc.columns[j].name;
rowAcc[colName] = colValue;
return rowAcc;
}, {});
acc.rows.push(rowObj);
}
return acc;
},
{
type: 'datatable',
columns: [],
rows: [],
}
);
},
};
}
开发者ID:elastic,项目名称:kibana,代码行数:81,代码来源:csv.ts
注:本文中的papaparse.parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论