Skip to content

Commit 28bdd72

Browse files
committed
fix #151; update readme; updat version
1 parent c08d22c commit 28bdd72

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

bin/options.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@
6666
"type":"string"
6767
},
6868
"--ignoreColumns": {
69-
"desc": "Columns to ignore on input. e.g. --ignoreColumns=# --ignoreColumns='[0,4,5]' ",
69+
"desc": "Columns to ignore on input. e.g. --ignoreColumns='[0,4,5, \"name\"]' ",
7070
"type": "~object"
7171
},
7272
"--includeColumns": {
73-
"desc": "Columns to include on input. e.g. --includeColumns=# --includeColumns='[0,4,5]' ",
73+
"desc": "Columns to include on input. e.g. --includeColumns='[0,4,5, \"title\"]' ",
7474
"type": "~object"
7575
}
7676
},

libs/core/Converter.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,21 @@ Converter.prototype.getEol = function (data) {
431431
return this.param.eol || eol;
432432
};
433433

434-
Converter.prototype.fromFile = function (filePath, cb) {
434+
Converter.prototype.fromFile = function (filePath, cb, options) {
435435
var fs = require('fs');
436436
var rs = null;
437+
if (typeof cb ==="object" && typeof options === "undefined"){
438+
options=cb;
439+
cb=null;
440+
}
437441
this.wrapCallback(cb, function () {
438442
if (rs && rs.destroy) {
439443
rs.destroy();
440444
}
441445
});
442446
fs.exists(filePath, function (exist) {
443447
if (exist) {
444-
rs = fs.createReadStream(filePath);
448+
rs = fs.createReadStream(filePath,options);
445449
rs.pipe(this);
446450
} else {
447451
this.emit('error', new Error("File not exists"));

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
"hireable": true
191191
}
192192
],
193-
"version": "1.1.4",
193+
"version": "1.1.5",
194194
"keywords": [
195195
"csv",
196196
"csv parser",

readme.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ csv()
9494

9595
```
9696

97+
Note that `.fromFile(filePath[ ,cb ,options])` takes an `options` parameter which will be passed to `fs.createReadStream()`. See [here](https://nodejs.org/dist/latest-v6.x/docs/api/fs.html#fs_fs_createreadstream_path_options) for docs.
98+
9799
### From CSV Stream
98100

99101
```js
@@ -270,8 +272,8 @@ Following parameters are supported:
270272
* **checkColumn**: whether check column number of a row is the same as headers. If column number mismatched headers number, an error of "mismatched_column" will be emitted.. default: false
271273
* **eol**: End of line character. If omitted, parser will attempt retrieve it from first chunk of CSV data. If no valid eol found, then operation system eol will be used.
272274
* **escape**: escape character used in quoted column. Default is double quote (") according to RFC4108. Change to back slash (\\) or other chars for your own case.
273-
* **includeColumns**: This parameter instructs the parser to include only those columns as specified by an array of column indexes. Example: [0,2,3] will parse and include only columns 0, 2, and 3 in the JSON output.
274-
* **ignoreColumns**: This parameter instructs the parser to ignore columns as specified by an array of column indexes. Example: [1,3,5] will ignore columns 1, 3, and 5 and will not return them in the JSON output.
275+
* **includeColumns**: This parameter instructs the parser to include only those columns as specified by an array of column indexes or header names. Example: [0,2,3,"name"] will parse and include only columns 0, 2, 3, and column with header "name" in the JSON output.
276+
* **ignoreColumns**: This parameter instructs the parser to ignore columns as specified by an array of column indexes or header names. Example: [1,3,5,"title","age"] will ignore columns 1, 3, 5, title column and age column and will not return them in the JSON output.
275277

276278
All parameters can be used in Command Line tool.
277279

@@ -585,6 +587,11 @@ There are some limitations when using multi-core feature:
585587

586588
#Change Log
587589

590+
## 1.1.5
591+
592+
* `ignoreColumns` and `includeColumns` now allow put in header names and indecies.
593+
* only include `child_process` when multi worker is needed.
594+
* allow `fs.createReadStream` options being passed in through `fromFile` function
588595

589596
## 1.1.4
590597

0 commit comments

Comments
 (0)