Skip to content

Commit 97c5bdf

Browse files
committed
fix: #139
1 parent 263353a commit 97c5bdf

8 files changed

Lines changed: 113 additions & 87 deletions

File tree

libs/core/defParam.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports=function(params){
44
delimiter: ',', // change the delimiter of csv columns. It is able to use an array to specify potencial delimiters. e.g. [",","|",";"]
55
quote: '"', //quote for a column containing delimiter.
66
trim: true, //trim column's space charcters
7-
checkType: true, //whether check column type
7+
checkType: false, //whether check column type
88
toArrayString: false, //stream down stringified json array instead of string of json. (useful if downstream is file writer etc)
99
ignoreEmpty: false, //Ignore empty value while parsing. if a value of the column is empty, it will be skipped parsing.
1010
workerNum: getEnv("CSV_WORKER",1), //number of parallel workers. If multi-core CPU available, increase the number will get better performance for large csv data.

libs/core/linesToJson.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function checkType(item, head, headIdx, param) {
172172
} else if (head.indexOf('string#!') > -1) {
173173
return param._headerType[headIdx] = stringType
174174
} else if (param.checkType) {
175-
return param._headerType[headIdx] = dynamicType(item)
175+
return param._headerType[headIdx] = dynamicType
176176
} else {
177177
return param._headerType[headIdx] = stringType
178178
}
@@ -194,17 +194,17 @@ function stringType(item) {
194194
function dynamicType(item) {
195195
var trimed = item.trim();
196196
if (trimed === "") {
197-
return stringType;
197+
return stringType(item);
198198
}
199199
if (numReg.test(trimed)) {
200-
return numberType
200+
return numberType(item)
201201
} else if (trimed.length === 5 && trimed.toLowerCase() === "false" || trimed.length === 4 && trimed.toLowerCase() === "true") {
202-
return booleanType;
202+
return booleanType(item);
203203
} else if (trimed[0] === "{" && trimed[trimed.length - 1] === "}" || trimed[0] === "[" && trimed[trimed.length - 1] === "]") {
204-
return jsonType;
204+
return jsonType(item);
205205

206206
} else {
207-
return stringType;
207+
return stringType(item);
208208
}
209209
}
210210

libs/core/rowSplit.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ module.exports=function rowSplit(rowStr, param) {
6262
}
6363
}
6464
}
65-
6665
return {cols:row,closed:!inquote};
6766
// if (param.workerNum<=1){
6867
// }else{

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Following parameters are supported:
238238
* **delimiter**: delimiter used for seperating columns. Use "auto" if delimiter is unknown in advance, in this case, delimiter will be auto-detected (by best attempt). Use an array to give a list of potential delimiters e.g. [",","|","$"]. default: ","
239239
* **quote**: If a column contains delimiter, it is able to use quote character to surround the column content. e.g. "hello, world" wont be split into two columns while parsing. Set to "off" will ignore all quotes. default: " (double quote)
240240
* **trim**: Indicate if parser trim off spaces surrounding column content. e.g. " content " will be trimmed to "content". Default: true
241-
* **checkType**: This parameter turns on and off whether check field type. default is true.
241+
* **checkType**: This parameter turns on and off whether check field type. default is false.
242242
* **toArrayString**: Stringify the stream output to JSON array. This is useful when pipe output to a file which expects stringified JSON array. default is false and only stringified JSON (without []) will be pushed to downstream.
243243
* **ignoreEmpty**: Ignore the empty value in CSV columns. If a column value is not giving, set this to true to skip them. Defalut: false.
244244
* **workerNum**: Number of worker processes. The worker process will use multi-cores to help process CSV data. Set to number of Core to improve the performance of processing large csv file. Keep 1 for small csv files. Default 1.
@@ -283,7 +283,7 @@ csv()
283283
})
284284
```
285285

286-
`csvRow` is always an array of strings no matter `checkType` value.
286+
`csvRow` is always an array of strings without types.
287287

288288
`csv` event is the fastest parse event while `json` and `data` event is about 2 times slower. Thus if `csv` is enough, for best performance, just use it without `json` and `data` event.
289289

@@ -549,6 +549,12 @@ There are some limitations when using multi-core feature:
549549

550550
#Change Log
551551

552+
553+
## 1.1.4
554+
555+
* default value of `checkType` is now false as it causes problems on some csv docs.
556+
* Added ignoreColumns and includeColumns features. #138
557+
552558
## 1.1.1
553559

554560
* Fix bugs: preProcessLine is not emitted

test/data/data#139

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
field1, field2, field3, field4,
2+
2005088801,A1,9001009395,
3+
2005088806,A6,9001009395 9001009990,
4+
2005088807,A7,9001009989,

test/data/dataIgnoreEmpty

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ d1,,d3,,world
77
d2,d,d,d,d
88
,,,,
99
d4,d2,d3
10+
11+
12+
13+

0 commit comments

Comments
 (0)