
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
csv-write-stream
Advanced tools
A CSV encoder stream that produces properly escaped CSVs.
A through stream. Write arrays of strings (or JS objects) and you will receive a properly escaped CSV stream out the other end.
var csvWriter = require('csv-write-stream')
var writer = csvWriter()
writer
is a duplex stream -- you can pipe data to it and it will emit a string for each line of the CSV
{
separator: ',',
newline: '\n',
headers: undefined,
sendHeaders: true
}
headers
can be an array of strings to use as the header row. if you don't specify a header row the keys of the first row written to the stream will be used as the header row IF the first row is an object (see the test suite for more details). if the sendHeaders
option is set to false, the headers will be used for ordering the data but will never be written to the stream.
example of auto headers:
var writer = csvWriter()
writer.pipe(fs.createWriteStream('out.csv'))
writer.write({hello: "world", foo: "bar", baz: "taco"})
writer.end()
// produces: hello,foo,baz\nworld,bar,taco\n
example of specifying headers:
var writer = csvWriter({ headers: ["hello", "foo"]})
writer.pipe(fs.createWriteStream('out.csv'))
writer.write(['world', 'bar'])
writer.end()
// produces: hello,foo\nworld,bar\n
example of not sending headers:
var writer = csvWriter({sendHeaders: false})
writer.pipe(fs.createWriteStream('out.csv'))
writer.write({hello: "world", foo: "bar", baz: "taco"})
writer.end()
// produces: world,bar,taco\n
see the test suite for more examples
$ npm install
$ npm test
This module also includes a CLI, which you can pipe ndjson to stdin and it will print csv on stdout. You can install it with npm install -g csv-write-stream
.
$ csv-write --help
usage: csv-write [-h] [-v] [--separator SEPARATOR] [--newline NEWLINE]
[--headers HEADERS [HEADERS ...]] [--no-send-headers]
A CSV encoder stream that produces properly escaped CSVs. JSON is read from
STDIN, formatted to CSV, and written to STDOUT.
Optional arguments:
-h, --help Show this help message and exit.
-v, --version Show program's version number and exit.
--separator SEPARATOR
The separator character to use. Defaults to ','.
--newline NEWLINE The newline character to use. Defaults to $'\n'.
--headers HEADERS [HEADERS ...]
The list of headers to use. If omitted, the keys of
the first row written to STDIN will be used
--no-send-headers Don't print the header row.
$ cat example.ndjson | csv-write > example.csv
FAQs
A CSV encoder stream that produces properly escaped CSVs.
The npm package csv-write-stream receives a total of 67,568 weekly downloads. As such, csv-write-stream popularity was classified as popular.
We found that csv-write-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.