Skip to content

Commit e772fa6

Browse files
committed
resolve conlifct
2 parents cd3d0eb + a027cea commit e772fa6

37 files changed

Lines changed: 816 additions & 762 deletions

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function(grunt) {
2424
client: {
2525
options: {
2626
mangle: true,
27-
banner:"/*Automatically Generated. Do not modify.*/\n"
27+
banner: "/*Automatically Generated. Do not modify.*/\n"
2828
},
2929
src: "./dist/csvtojson.js",
3030
dest: "./dist/csvtojson.min.js",

bin/benchmark.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
#!/usr/bin/env node
2-
var path=process.argv[2];
3-
var fs=require('fs');
4-
if (!fs.existsSync(path)){
2+
var path = process.argv[2];
3+
var fs = require('fs');
4+
if (!fs.existsSync(path)) {
55
console.log("Run: benchmark [csvpath]");
6-
console.log("File not found: ",path);
6+
console.log("File not found: ", path);
77
process.exit(1);
88
}
9-
function testCSVLine(coreNum,checkType,cb){
10-
console.log("WorkerNum:",coreNum,"Check Type: ",checkType);
11-
var Converter=require("../libs/core/Converter");
12-
var rs=fs.createReadStream(path);
13-
var converter=new Converter({
14-
workerNum:coreNum,
15-
checkType:checkType,
16-
constructResult:false
9+
function testCSVLine(coreNum, checkType, cb){
10+
console.log("WorkerNum:", coreNum, "Check Type: ", checkType);
11+
var Converter = require("../libs/core/Converter");
12+
var rs = fs.createReadStream(path);
13+
var converter = new Converter({
14+
workerNum: coreNum,
15+
checkType: checkType,
16+
constructResult: false
1717
// fork:true
1818
});
19-
var totalLines=0;
20-
var secLines=0;
21-
converter.on("data",function(){
22-
totalLines++;
23-
secLines++;
19+
var totalLines = 0;
20+
var secLines = 0;
21+
converter.on("data", function() {
22+
totalLines++;
23+
secLines++;
2424
});
25-
converter.on("end",function(){
25+
converter.on("end", function() {
2626
clearInterval(timer);
2727
console.log("");
28-
var t=new Date()-start;
29-
console.log("Time elapsed: ",t, " ms");
30-
console.log("Total lines: "+totalLines);
31-
console.log("Average Speed: "+Math.round(totalLines/t*1000)+" Lines / Sec");
28+
var t = new Date() - start;
29+
console.log("Time elapsed: ", t, " ms");
30+
console.log("Total lines: " + totalLines);
31+
console.log("Average Speed: " + Math.round(totalLines / t * 1000) + " Lines / Sec");
3232
cb();
33-
})
34-
var timer=setInterval(function(){
35-
process.stdout.write("\r"+secLines+" CSV Lines/Sec");
36-
secLines=0;
37-
},1000);
38-
var start=new Date();
33+
});
34+
var timer = setInterval(function() {
35+
process.stdout.write("\r" + secLines + " CSV Lines/Sec");
36+
secLines = 0;
37+
}, 1000);
38+
var start = new Date();
3939

40-
var stream=rs.pipe(converter);
40+
var stream = rs.pipe(converter);
4141
}
4242

4343
// testCSVLine(1,false,false,function(){

bin/csvtojson.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function csvtojson() {
6868
}
6969
}
7070
process.exit(1);
71-
})
71+
});
7272
is.pipe(conv).pipe(process.stdout);
7373
// is.pipe(conv);
7474
}

bin/genCsv.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
#!/usr/bin/env node
2-
var minimist=require("minimist");
3-
var argv=process.argv;
2+
var minimist = require("minimist");
3+
var argv = process.argv;
44
argv.shift();
55
argv.shift();
6-
var args=minimist(argv);
7-
var headers=["name","header1","file2","description","header2","field2","header3"];
6+
var args = minimist(argv);
7+
var headers = ["name", "header1", "file2", "description", "header2", "field2", "header3"];
88

9-
if (args.headers){
10-
headers=JSON.parse(args.headers);
9+
if (args.headers) {
10+
headers = JSON.parse(args.headers);
1111
}
12-
var rowNum=args.row?args.row:10000;
13-
var chars=args.chars?args.chars:"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
14-
var maxLength=parseInt(args.max?args.max:"15");
12+
var rowNum = args.row ? args.row : 10000;
13+
var chars = args.chars ? args.chars : "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
14+
var maxLength = parseInt(args.max ? args.max : "15");
1515
console.log(headers.join(","));
16-
for (var i=0;i<rowNum;i++){
17-
var row=[];
18-
for (var j=0;j<headers.length;j++){
16+
for (var i = 0; i < rowNum; i++) {
17+
var row = [];
18+
for (var j = 0; j < headers.length; j++) {
1919
row.push(genWord());
2020
}
2121
console.log(row.join(","));
2222
}
2323

24-
25-
function genWord(){
26-
var len=Math.round(Math.random()*maxLength);
27-
var rtn="";
28-
for (var i=0;i<len;i++){
29-
var pos=Math.round(Math.random()*chars.length);
30-
rtn+=chars[pos];
24+
function genWord() {
25+
var len = Math.round(Math.random() * maxLength);
26+
var rtn = "";
27+
for (var i = 0; i < len; i++) {
28+
var pos = Math.round(Math.random() * chars.length);
29+
rtn += chars[pos];
3130
}
3231
return rtn;
3332
}

bin/options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"type": "boolean"
1818
},
1919
"--checkType": {
20-
"desc": "This parameter turns on and off whether check field type. default is true.",
20+
"desc": "This parameter turns on and off whether check field type. default is false.",
2121
"type": "boolean"
2222

2323
},

libs/core/CSVError.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
var util=require("util");
2-
module.exports=CSVError;
3-
function CSVError(err,index,extra){
4-
Error.call(this,"");
5-
this.err=err;
6-
this.line=index;
7-
this.extra=extra;
8-
this.message="Error: "+err+". JSON Line number: "+index+ (extra?" near: "+extra:"");
9-
this.name="CSV Error";
1+
var util = require("util");
2+
module.exports = CSVError;
3+
function CSVError(err, index, extra) {
4+
Error.call(this, "");
5+
this.err = err;
6+
this.line = index;
7+
this.extra = extra;
8+
this.message = "Error: " + err + ". JSON Line number: " + index + (extra ? " near: " + extra : "");
9+
this.name = "CSV Error";
1010
}
11-
util.inherits(CSVError,Error);
11+
util.inherits(CSVError, Error);
1212

13-
CSVError.prototype.toString=function(){
14-
return JSON.stringify([this.err,this.line,this.extra]);
15-
}
13+
CSVError.prototype.toString = function() {
14+
return JSON.stringify([this.err, this.line, this.extra]);
15+
};
1616

17-
CSVError.column_mismatched=function(index,extra){
18-
return new CSVError("column_mismatched",index,extra);
19-
}
17+
CSVError.column_mismatched = function(index, extra) {
18+
return new CSVError("column_mismatched", index, extra);
19+
};
2020

21-
CSVError.unclosed_quote=function(index,extra){
22-
return new CSVError("unclosed_quote",index,extra);
23-
}
21+
CSVError.unclosed_quote = function(index, extra) {
22+
return new CSVError("unclosed_quote", index, extra);
23+
};
2424

25-
CSVError.fromArray=function(arr){
26-
return new CSVError(arr[0],arr[1],arr[2]);
27-
}
25+
CSVError.fromArray = function(arr) {
26+
return new CSVError(arr[0], arr[1], arr[2]);
27+
};

0 commit comments

Comments
 (0)