本文整理汇总了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);
});
开发者ID:toastermagic,项目名称:plaques,代码行数:31,代码来源:index.ts
示例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);
}
开发者ID:aceslick911,项目名称:sandwichstation,代码行数:28,代码来源:generateTestData.ts
示例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);
});
开发者ID:ideal-postcodes,项目名称:postcode.js,代码行数:13,代码来源:exhaustive_unit.ts
示例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...');
开发者ID:kimsk,项目名称:try-typescript,代码行数:28,代码来源:app.ts
示例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));
});
});
开发者ID:tae-jun,项目名称:csv-viewer,代码行数:83,代码来源:index.ts
注:本文中的csv-parse.default函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论