本文整理汇总了TypeScript中csv-parse.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: parse
var p = new Promise<any>((res, rej) => {
console.log('parsing csv file', filePath);
var plaqueList = [];
var parser = parse({ delimiter: ',' }, (err, data) => {
if (err) {
rej(err);
return;
}
var cols = data[0];
for (var index = 1; index < data.length; index++) {
var newPlaque: any = _.object(cols, data[index]);
if (!newPlaque.main_photo
|| !newPlaque.erected
|| newPlaque.erected.startsWith('16')
|| newPlaque.erected.startsWith('17')
|| newPlaque.erected.startsWith('18')) {
continue;
}
newPlaque.search_key = getSearchKey(newPlaque);
newPlaque.erected_decade = newPlaque.erected.substring(0, 3) + '0';
plaqueList.push(newPlaque);
};
res(plaqueList);
});
fs.createReadStream(filePath).pipe(parser);
});
示例2: convertCSVToJSON
function convertCSVToJSON(domain:string, version:string, inFile:string, outfile:string){
var parser = parse({delimiter: ','}, function(err, data){
var header=[];
var jsonData=[];
for(var row of data){
if(header.length==0){
for(var col of row){
header.push(col);
}
} else {
var i=0;
var rowData={
domain,
version
};
for(var col of row){
rowData[header[i]] = col;
i++;
}
jsonData.push(rowData);
}
}
fs.writeFile(outfile, JSON.stringify(jsonData,null, 4));
});
fs.createReadStream(inFile).pipe(parser);
}
示例3: before
before(function(done) {
this.timeout(TIMEOUT);
console.log(
"Loading in complete array of postcodes (this might take a while)..."
);
const inputFile = resolve(__dirname, "./data/postcodes.csv.gz");
createReadStream(inputFile)
.pipe(createGunzip())
.pipe(parse({ delimiter: "," }))
.on("data", (data: CsvRecord) => testData.push(data[0]))
.on("error", done)
.on("end", done);
});
示例4: require
import * as _ from 'lodash';
import * as sqlite3 from 'sqlite3';
import * as fs from 'fs';
var parse = require('csv-parse');
var parser = parse({delimiter: ';'}, function(err, data){
console.log(data);
});
fs.createReadStream(__dirname+'/../fs_read.csv').pipe(parser);
var db = new sqlite3.Database('test.db');
db.run("INSERT INTO memos VALUES('TEST', 5000)");
db.each("SELECT * FROM memos", (err, row) => {
console.log(row.text);
});
db.close();
let arr: number[] = [1, 2, 3];
_.forEach(arr, (v) => console.log(v));
console.log('running...');
示例5: parse
fsManager.getLogFile(logName, (err, log:string)=> {
// Parse CSV string
parse(log, function (err, records:any[][]) {
// Get node and sensor information from header row
var nodeNames = records.shift();
var sensors = records.shift();
// Remove header column
nodeNames.shift();
sensors.shift();
var data = {};
/**
* Process records
*/
// Collect nodes & sensors
records.forEach((record, index, arr)=> {
var dateStr = record.shift();
var date:Date = moment(dateStr, 'YYMMDD_HHmmss');
//dates.push(date);
record.filter((value, index, arr)=> {
if (value == '')
return false;
var nodeName = nodeNames[index];
var sensorName = sensors[index];
if (data[nodeName] == undefined)
data[nodeName] = {};
if (!Array.isArray(data[nodeName][sensorName]))
data[nodeName][sensorName] = [];
data[nodeName][sensorName].push(
{
value: Number(value),
//date: dates[index]
date: date
});
});
});
// Change data structure: Object -> Array
var nodes = [];
// Node processing
for (var nodeName in data) {
var node = {
name: nodeName,
sensors: []
};
// Sensor processing
for (var sensorName in data[node.name]) {
var log = data[node.name][sensorName];
var sensor = {
name: sensorName,
log: log
};
// Filter log
sensor.log = sensor.log.filter((record, index, arr)=> {
if (index == 0)
return true;
return record['value'] != arr[index - 1].value;
});
// Push sensor
node.sensors.push(sensor);
}
// Push node
nodes.push(node);
}
// Set date string
nodes.forEach((node)=> {
node.sensors.forEach((sensor:any)=> {
sensor.log.forEach((record:any)=> {
record.date = new Date(record.date).toLocaleTimeString();
})
});
});
// Response
res.json(new Res(err, nodes));
});
});