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


TypeScript csv-parse.default函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。