Skip to content

Commit cc6502f

Browse files
committed
add simple cli tool
1 parent a2a74e0 commit cc6502f

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Readme.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,29 @@ In order for the inputEncoding option to take effect you need to install [iconv-
7373
Also, take a look at the iconv-lite documentation for supported encodings.
7474
(iconv-lite provides pure javascript character encoding conversion -> no native code compilation)
7575

76+
## CLI
77+
78+
To use on the command line install it globally:
79+
80+
```bash
81+
$ npm install csv-streamify -g
82+
```
83+
84+
This should add the `csv-streamify` command to your `$PATH`.
85+
86+
Then, you either pipe data into it or give it a filename:
87+
88+
```bash
89+
# pipe data in
90+
$ cat some_data.csv | csv-streamify
91+
# pass a filename
92+
$ csv-streamify some_data.csv > output.json
93+
# tell csv-streamify to read from + wait on stdin
94+
$ csv-streamify -
95+
```
96+
7697
## Wishlist
7798

78-
- CLI
7999
- browser support
80100

81101
If you would like to contribute either of those just open an issue so we can discuss it further. :)

cli.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env node
2+
3+
var csv = require('./csv-streamify')
4+
5+
var arg = process.argv[2]
6+
var opts = { encoding: 'utf8' }
7+
8+
if (!process.stdin.isTTY || arg === '-') {
9+
process.stdin.pipe(csv(opts)).pipe(process.stdout)
10+
} else {
11+
var fs = require('fs')
12+
fs.createReadStream(arg).pipe(csv(opts)).pipe(process.stdout)
13+
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"scripts": {
1111
"test": "./node_modules/.bin/mocha -R spec"
1212
},
13+
"bin": {
14+
"csv-streamify": "cli.js"
15+
},
1316
"repository": "https://github.com/klaemo/csv-stream",
1417
"keywords": [
1518
"csv",

0 commit comments

Comments
 (0)